Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
52 views11 pages

Synch Table

ExAcquireGuardedMutex a resource. Use in passive- PASSIVE_LEVEL or Windows 2000 level or APC-level code that APC_LEVEL through Release: ExReleaseGuardedMutex cannot be reentered while Windows 7 holding the lock. During use: No change Server: Windows The driver is responsible for Server 2003 ensuring that APCs are not through delivered while it holds the Windows 2008 guarded mutex. R2 Spin lock (KSPIN_LOCK) Provides exclusive access to To acquire: All disabled No Client: a resource for a very
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views11 pages

Synch Table

ExAcquireGuardedMutex a resource. Use in passive- PASSIVE_LEVEL or Windows 2000 level or APC-level code that APC_LEVEL through Release: ExReleaseGuardedMutex cannot be reentered while Windows 7 holding the lock. During use: No change Server: Windows The driver is responsible for Server 2003 ensuring that APCs are not through delivered while it holds the Windows 2008 guarded mutex. R2 Spin lock (KSPIN_LOCK) Provides exclusive access to To acquire: All disabled No Client: a resource for a very
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

Summary of Windows

Synchronization Primitives
October 25, 2010

Abstract

This paper summarizes the synchronization primitives available to kernel-mode


drivers for the Microsoft® Windows® family of operating systems.
This information applies for the following operating systems:
Windows Server® 2008 R2
Windows 7
Windows Server 2008
Windows Vista®
Microsoft Windows Server 2003
Microsoft Windows XP
Microsoft Windows 2000
References and resources discussed here are listed at the end of this paper.
The current version of this paper is maintained on the Web at:
http://www.microsoft.com/whdc/driver/tips/SyncPrimitives.mspx

Disclaimer: This document is provided “as-is”. Information and views expressed in this document,
including URL and other Internet Web site references, may change without notice. You bear the risk of
using it.
This document does not provide you with any legal rights to any intellectual property in any Microsoft
product. You may copy and use this document for your internal, reference purposes.
© 2010 Microsoft Corporation. All rights reserved.

Date Change
October 23, 2010 Added threaded DPC primitives
Summary of Windows Synchronization Primitives - 2

June 20, 2005 First publication

Contents
Summary of Windows Synchronization Primitives 3
Windows Kernel-Mode Synchronization Primitives 4
Resources 10

October 21, 2010


© 2010 Microsoft Corporation. All rights reserved.
Summary of Windows Synchronization Primitives - 3

Summary of Windows Synchronization Primitives


Microsoft® Windows® supports numerous synchronization primitives, each of which
has unique characteristics. In any situation, the best primitive to use depends on the
operations that require synchronization. The table in this document lists the
synchronization primitives that are available to kernel-mode drivers along with the
characteristics of each primitive. It includes the following information:
Primitive—Lists the name of the primitive, the name of the data types used to
represent it (if any), and the device driver interfaces (DDIs) that acquire and release
it.
Usage—Describes the type of synchronization the primitive provides and the
situations in which to use it.
IRQL—Lists the IRQL at which a caller can invoke the primitive and the IRQL at
which code that is protected by the primitive runs.
Effect on APCs—Indicates whether user, normal kernel, and special kernel
asynchronous procedure calls (APCs) can be delivered to the thread while the
primitive is in use. Windows supports three types of APCs:
 User APCs run in user mode and are delivered during the unwind from
kernel mode to user mode. This type of APC is used for thread termination and
user-mode signaling operations.
 Normal kernel APCs are used for thread suspension and hard error pop-
ups unless delivery has been disabled using KeEnterCriticalRegion. They run in
kernel mode at PASSIVE_LEVEL
 Special kernel APCs run in kernel mode at APC_LEVEL and are used in IRP
completion.
Recursive acquisition—Indicates whether the primitive can be acquired
recursively, and thus whether it can be used safely in reentrant code.
Operating system support—Lists the Windows client and server operating system
releases that support this primitive.

October 21, 2010


© 2010 Microsoft Corporation. All rights reserved.
Windows Kernel-Mode Synchronization Primitives
Primitive Usage IRQL Effect on APCs Recursive Operating
acquisition? system support
Mutex (KMUTEX) Provides exclusive access to To acquire: While waiting to Yes, by the Client:
a resource. Use in passive- PASSIVE_LEVEL acquire a mutex: same thread Windows 2000
Acquire: KeWaitXxx level code that might be Delivery of APCs through
reentered while holding the During use: No depends on the Windows 7
lock. change values of the
WaitMode and Server:
Alertable Windows
parameters to the Server 2003
KeWaitXxx through
routine.1 Windows 2008
R2
While holding a
mutex:
User APCs:
Disabled

Normal kernel
APCs: Disabled

Special kernel
APCs: Delivered
and executed
Primitive Usage IRQL Effect on APCs Recursive Operating
acquisition? system support
Fast mutex (FAST_MUTEX) Provides exclusive access to To acquire: All disabled No Client:
a resource. Use in passive- PASSIVE_LEVEL or Windows 2000
Acquire: ExAcquireFastMutex or level or APC-level code that APC_LEVEL through
ExTryToAcquireFastMutex cannot be reentered while Windows 7
Release: ExReleaseFastMutex holding the lock. During use:
APC_LEVEL Server:
Windows
Server 2003
through
Windows 2008
R2r
Unsafe fast mutex (FAST_MUTEX) Provides exclusive access to To acquire: Not disabled No Client:
a resource. Use in passive- PASSIVE_LEVEL or Windows 2000
Acquire: ExAcquireFastMutexUnsafe level or APC-level code that APC_LEVEL through
cannot be reentered while Windows 7
Release: ExReleaseFastMutexUnsafe holding the lock. During use: No
change Server:
The driver is responsible for Windows
ensuring that APCs are not Server 2003
delivered while it holds the through
unsafe fast mutex. Windows 2008
R2

1
For more information, see “Waits and APCs” in the Windows Driver Kit (WDK).
?
For more information, see “Threaded DPCs” in the Windows Driver Kit (WDK).
Primitive Usage IRQL Effect on APCs Recursive Operating
acquisition? system support
Guarded mutex (KGUARDED_MUTEX) Provides exclusive access to To acquire: All disabled No Client:
a resource. Use in passive- PASSIVE_LEVEL or Windows Vista
Acquire: KeAcquireGuardedMutex or level or APC-level code that APC_LEVEL through
KeTryToAcquireGuardedMutex cannot be reentered while Windows 7
Release: KeReleaseGuardedMutex holding the lock. During use: No
change Server:
Disables all APCs but does Windows
not raise IRQL to APC_LEVEL. Server 2003
Does not require through
reprogramming the CPU Task Windows 2008
Priority Register (TPR), which R2
is used for routing interrupts
in the I/O APIC on a
multiprocessor system,
thereby improving
performance over fast
mutexes.
Critical region Prevents thread suspension. To acquire: User APCs: Recursive up Client:
PASSIVE_LEVEL or Disabled to 2^31 Windows 2000
Enter: KeEnterCriticalRegion Use in file systems and file APC_LEVEL times through
system filters to prevent Normal kernel Windows 7
Leave: KeLeaveCriticalRegion thread suspension while During use: No APCs: Disabled
holding a kernel dispatcher change Server:
object lock such as an event, Special kernel Windows
semaphore, or mutex. APCs: Delivered Server 2003
and executed through
Windows 2008
R2
Primitive Usage IRQL Effect on APCs Recursive Operating
acquisition? system support
Guarded region Disables all APCs but does To acquire: All disabled Recursive up Client:
not raise IRQL to APC_LEVEL. PASSIVE_LEVEL or to 2^31 Windows Vista
Enter: KeEnterGuardedRegion Re-enables APCs after the APC_LEVEL times through
thread exits the outermost Windows 7
Leave: KeLeaveGuardedRegion guarded region. During use: No
change Server:
Use instead of raising IRQL to Windows
APC_LEVEL. Server 2003
through
Windows 2008
R2
Executive resource (ERESOURCE) Provides a read/write lock. To acquire: Not disabled Yes, by the Client:
Use in passive-level or APC- PASSIVE_LEVEL or same thread Windows 2000
Acquire: ExAcquireResourceSharedLite, level code that usually APC_LEVEL through
ExAcquireSharedStarveExclusive, or requires shared access, but Windows 7
ExTryToAcquireResourceExclusiveLite occasionally requires During use: No
Release: ExReleaseResourceForThread exclusive access. change Server:
Windows
Server 2003
through
Windows 2008
R2
Event (KEVENT) Blocks execution of the To acquire: Not disabled. No thread Client:
current thread until some PASSIVE_LEVEL or Delivery of APCs ownership Windows 2000
Acquire: KeWaitXxx other thread signals that an APC_LEVEL depends on the through
event has occurred. values of the Windows 7
During use: No WaitMode and
change Alertable Server:
parameters to the Windows
KeWaitXxx Server 2003
routine.Error: through
Reference source Windows 2008
not found R2
Primitive Usage IRQL Effect on APCs Recursive Operating
acquisition? system support
Semaphore (KSEMAPHORE) Provides shared access to a To acquire: Not disabled; No thread Client:
resource. Use in passive-level PASSIVE_LEVEL or delivery of APCs ownership Windows 2000
Acquire: KeWaitXxx or APC-level code. APC_LEVEL depends on the through
values of the Windows 7
Release: KeReleaseSemaphore During use: No WaitMode and
change Alertable Server:
parameters to the Windows
KeWaitXxx Server 2003
routine.Error: through
Reference source Windows 2008
not found R2
Executive spin lock (KSPIN_LOCK) Provides exclusive access to To acquire: All disabled No Client:
a resource at DISPATCH_LEVEL Windows 2000
Acquire: KeAcquireSpinLock, DISPATCH_LEVEL. or lower through
KeAcquireSpinLockAtDpcLevel, or Windows 7
KeTryToAcquireSpinLockAtDpcLevel During use:
DISPATCH_LEVEL Server:
Release: KeReleaseSpinLock or Windows
KeReleaseSpinLockFromDpcLevel Server 2003
through
Windows 2008
R2
Executive spin lock (KSPIN_LOCK) Provides exclusive access to To acquire: All disabled No Client:
a resource at DISPATCH_LEVEL Windows Vista
Acquire: KeAcquireSpinLockForDpc DISPATCH_LEVEL. or lower through
Windows 7
Release: KeReleaseSpinLockForDpc Note: These primitives can During use:
only be called from a DISPATCH_LEVEL Server:
CustomThreadedDPC routine Windows
of a threaded DPC object.2 Server 2008
through
Windows 2008
R2r
Summary of Windows Synchronization Primitives - 9

Primitive Usage IRQL Effect on APCs Recursive Operating


acquisition? system support
Queued spin lock (KSPIN_LOCK, Provides exclusive access to To acquire: All disabled No Client:
KLOCK_QUEUE_HANDLE) a resource at DISPATCH_LEVEL Windows XP
DISPATCH_LEVEL. or lower through
Acquire: KeAcquireInStackQueuedSpinLock, or Windows 7
KeAcquireInStackQueuedSpinLockAtDpcLevel During use:
DISPATCH_LEVEL Server:
Release: KeReleaseInStackQueuedSpinLock, or Windows
KeReleaseInStackQueuedSpinLockFromDpcLevel Server 2003
through
Windows 2008
R2
Queued spin lock (KSPIN_LOCK, Provides exclusive access to To acquire: All disabled No Client:
KLOCK_QUEUE_HANDLE) a resource at DISPATCH_LEVEL Windows Vista
DISPATCH_LEVEL. or lower through
Acquire:KeAcquireInStackQueuedSpinLockForDpc Windows 7
Note: These primitives can During use:
Release: KeReleaseInStackQueuedSpinLockForDpc only be called from a DISPATCH_LEVEL Server:
CustomThreadedDPC routine Windows
of a threaded DPC object.2 Server 2008
through
Windows 2008
R2r
Interrupt spin lock (KINTERRUPT) Provides exclusive access to To acquire: DIRQL All disabled No Client:
a resource at IRQL greater or lower Windows XP
Acquire: KeAcquireInterruptSpinLock than DISPATCH_LEVEL. through
On Windows 2000, use During use: DIRQL Windows 7
Release: KeReleaseInterruptSpinLock KeSynchronizeExecution
with a SynchCritSection Server:
routine to raise IRQL to Windows
DIRQL for the device. Server 2003
through
Windows 2008
R2

October 21, 2010


© 2010 Microsoft Corporation. All rights reserved.
Summary of Windows Synchronization Primitives - 10

Primitive Usage IRQL Effect on APCs Recursive Operating


acquisition? system support
Timer object (KTIMER) Delays execution of current To acquire: Not applicable Not Client:
thread for specified period of DISPATCH_LEVEL applicable Windows 2000
Acquire: KeWaitXxx time or performs a one-time or lower through
or periodic operation in a Windows 7
DPC associated with the During use:
timer. Associated DPC is Server:
called at Windows
DISPATCH_LEVEL Server 2003
through
Windows 2008
R2

October 21, 2010


© 2010 Microsoft Corporation. All rights reserved.
Summary of Windows Synchronization Primitives - 11

Resources
WHDC website:
Locks, Deadlocks, and Synchronization
http://www.microsoft.com/whdc/driver/kernel/locks.mspx
Windows Driver Kit (WDK)
http://www.microsoft.com/whdc/DevTools/default.mspx

MSDN website:
Waits and APCs
http://msdn.microsoft.com/en-us/library/ff565592(VS.85).aspx
Synchronization Techniques
http://msdn.microsoft.com/en-us/library/ff564522(VS.85).aspx
Threaded DPCs
http://msdn.microsoft.com/en-us/library/ff564621(VS.85).aspx

October 21, 2010

You might also like