WDFCOLLECTION Concurrency

Does WdfCollectionAdd allow for concurrent insertion without explicitly aquiring a lock similar to the interlocked list functions or must a lock be acquired reguardless of operation? Thanks.

Yes, insertions into a collection are properly protected by the Framework.

Peter
OSR

Thanks peter, serialized access to the collection is only required if the collection is under interation? Or more accurately, removes only need to be blocked during iteration? Everything else is atomic. I have seen so many collection frameworks, some never acquire interal locks assuming the caller has the best idea of the locking semantics required, others are fully thread safe except iteration.

Yes… Each INDIVIDUAL DDI dealing with KMDF collections is properly serialized to make it thread-safe.

Of course there is no such guarantee between two or more calls to framework DDIs. Thus, if you get the number of entries in the collection (for example) and then attempt to enumerate that number of entries, there’s no guarantee that the collection won’t have changed between calls.

Hope that was clear,

Peter
OSR

Peter is correct. The framework collection is internally consistent, but you must provide your own synchronization to make sure that multiple concurrent accesses to the collection yield the results you want. For instance w/out additional synch from your driver, WdfCollectionRemoveItem(collection, 0) called concurrently from 2 threads will not return the same item since the collection maintains its own state, but if 2 threads are calling WdfCollectionGetItem(collection, 0) and another is adding an item at the same time, results will vary :wink:

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: Tuesday, January 15, 2008 1:41 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WDFCOLLECTION Concurrency

Yes… Each INDIVIDUAL DDI dealing with KMDF collections is properly serialized to make it thread-safe.

Of course there is no such guarantee between two or more calls to framework DDIs. Thus, if you get the number of entries in the collection (for example) and then attempt to enumerate that number of entries, there’s no guarantee that the collection won’t have changed between calls.

Hope that was clear,

Peter
OSR


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Thanks Doron/Peter.