Synchronization and Threaded DPCs

To synchronize access to a memory location that is accessed from both inside and outside a CustomThreadedDpc routine, a driver can use ordinary spin locks or queued spin locks. When doing so, the driver must obey certain rules to correctly synchronize at IRQL = PASSIVE_LEVEL and at IRQL = DISPATCH_LEVEL, because a CustomThreadedDpc routine can execute at both IRQLs.

For an ordinary spin lock, the following rules apply:

The rules for queued spin locks are similar:

Because KeAcquireSpinLockForDpc and KeAcquireInStackQueuedSpinLockForDpc do not reset the IRQL when called at DISPATCH_LEVEL, they execute faster than KeAcquireSpinLock and KeAcquireInStackQueuedSpinLock, respectively.

For more information about spin locks, see Spin Locks.