Share via


Spin Locks (Windows CE 5.0)

Send Feedback

A spin lock is a synchronization mechanism for protecting resources shared by kernel-mode threads. A spin lock handles synchronization among various threads of execution running concurrently. A thread acquires a spin lock before accessing protected resources. Only the thread holding the spin lock can use the resource and only until the lock is released. The spin lock prevents other threads from accessing the resource. While waiting for the spin lock to release, another thread can initiate a loop that attempts to acquire the spin lock and continues looping until the thread that holds the lock releases the spin lock.

For example, the MiniportSend function might queue packets passed to it by a protocol driver. Because other driver functions also use this queue, MiniportSend must protect the queue with a spin lock so that only one thread at a time can manipulate the links or contents. MiniportSend acquires the spin lock, adds the packet to the queue, and then releases the spin lock. By using a spin lock, MiniportSend ensures that the thread holding the lock is the only thread modifying the queue links while the packet is safely added to the queue. When the NIC driver removes the packets from the queue, the same spin lock protects its access. When a driver executes instructions that modify the head of the queue or any of the link fields making up the queue, the driver must protect the queue with a spin lock.

A well-written network driver will minimize the amount of time a particular thread holds a spin lock and, at the same time, not overprotect a queue. For example, your driver can perform some operations outside the region protected by the spin lock, such as filling in the length of a packet before it queues the packet. In addition, once the packet is in the queue and the executing thread releases the spin lock, the driver must assume that other threads can de-queue the packet immediately.

See Also

NDIS Synchronization | MiniportSend | NdisAcquireSpinLock | NdisAllocateSpinLock | NdisDprAcquireSpinLock | NdisDprReleaseSpinLock | NdisFreeSpinLock | NdisReleaseSpinLock

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.