The critical section object provides intraprocess synchronization. The current implementation uses the Microsoft® Win32® application programming interfaces (APIs) that use the CRITICAL_SECTION type.
The safest way to use CCritSec objects is to lock them with a CAutoLock object that guarantees to unlock the object when it goes out of scope and compiles to efficient inline code.
Member Functions
Name | Description |
CCritSec | Constructs a CCritSec object. |
Lock | Locks the critical section object. |
Unlock | Unlocks the critical section object. |
Constructs a CCritSec object.
CCritSec( );
No return value.
Calls the Microsoft® Win32® InitializeCriticalSection function to set the private critical section member variable. The destructor calls the Win32 DeleteCriticalSection function.
Locks the critical section object.
void Lock( );
No return value.
This member function locks the critical section object. You can make multiple lock calls on the same thread, but the CCritSec::Unlock member function must be called a corresponding number of times before the object is unlocked. If the object is locked by another thread, the CCritSec::Lock member function blocks until either the object is released or a "possible deadlock" exception occurs.
Releases the lock on the object acquired by calling the CCritSec::Lock member function.
void Unlock( );
No return value.
You must call the CCritSec::Unlock member function once for each call to Lock.
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.