1.3.23 Synchronization

Along with multi-threading and preemption in the Win32 system, a set of synchronization objects have been included. These objects provide the tools necessary to build reliable and robust multi-threaded applications.

The Win32 synchronization objects are:

Critical sections. This object may only be shared by threads within a single process. It provides a very fast mechanism for controlling mutual exclusive access to a resource.

Events. This object is used to record the occurrence of an event and synchronize it with some action.

Mutexes. Like critical sections, this object provides a mechanism for controlling mutual exclusive access to a resource. Mutexes are not restricted to threads within a single process, but are slightly slower.

Semaphores. A semaphore object is used to control access to a resource, but not necessarily in a mutually exclusive fashion. A semaphore object acts as a gate through which a variable number of threads may pass concurrently, up to a specified limit. The gate is open (Signaled state) as long as there are resources available. When the number of resources specified by the limit are concurrently in use, the gate is closed (Not-Signaled state).

For additional information on how to use the synchronization functionality, see the Synchronization Overview.

The synchronization functions include:

Function Description

DeleteCriticalSection Deletes a critical section object
EnterCriticalSection Used to gain exclusive access to a resource
InitializeCriticalSection Initializes a critical section
LeaveCriticalSection Releases exclusive access to a resource
CreateEvent Creates an event object
OpenEvent Opens a event object
PulseEvent Sets the event to signaled state and then resets it
ResetEvent Sets the event to the not-signaled state
SetEvent Sets the event to the signaled state
CreateMutex Creates a mutex object
OpenMutex Opens a mutex object
ReleaseMutex Releases ownership of a mutex object
CreateSemaphore Creates a semaphore object
ReleaseSemaphore Releases ownership of a semaphore object
OpenSemaphore Opens a named semaphore object
InterlockedDecrement Subtracts 1 from a count.
InterlockedIncrement Adds 1 to a count.
MsgWaitForMultipleObjects Blocks waiting for an object or message
WaitForMultipleObjects Blocks on multiple waitable objects
WaitForSingleObject Blocks on a single waitable object