Critical Section
The critical section object is a synchronization object that can be used for mutual exclusion
amongst threads of a single process. The critical section object is not a kernel object. The
critical section object is first created by initializing a CRITICAL_SECTION structure with the
InitializeCriticalSection function. The CRITICAL_SECTION structure is opaque and is not
meant to be public. The function EnterCriticalSection function blocks until no other thread is
in the critical section. After a thread has finished inside the critical section, it calls the
LeaveCriticalSection function. The TryEnterCriticalSection function is a non-blocking
function that can be used to test entry to a critical section code. Finally, the
DeleteCriticalSection function is used to delete the critical section object. These critical section
functions are very efficient and are more usable then the interlocked synchronization functions.
Proto-Type
VOID InitializeCriticalSection
(
LPCRITICAL_SECTION lpCriticalSection
// address of critical section object
);
Info:
The function initializes a critical section object through the
CRITICAL_SECTION structure.
Proto-Type
VOID EnterCriticalSection
(
LPCRITICAL_SECTION lpCriticalSection
// address of critical section object
);
Info:
The function blocks till entry to critical section of code is permited. The
function will not block, if the thread has already entered the critical section
code.
Proto-Type
VOID LeaveCriticalSection
(
LPCRITICAL_SECTION lpCriticalSection
// address of critical section object
);
Info:
The function can be called when a thread is about to leave a critical section of
code.