## CCritSec Class

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.

###

CCritSec::CCritSec

CCritSec Class

Constructs a CCritSec object.

CCritSec( );

##### Return Values

No return value.

##### Remarks

Calls the Microsoft® Win32® InitializeCriticalSection function to set the private critical section member variable. The destructor calls the Win32 DeleteCriticalSection function.

###

CCritSec::Lock

CCritSec Class

Locks the critical section object.

void Lock( );

##### Return Values

No return value.

##### Remarks

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.

###

CCritSec::Unlock

CCritSec Class

Releases the lock on the object acquired by calling the CCritSec::Lock member function.

void Unlock( );

##### Return Values

No return value.

##### Remarks

You must call the CCritSec::Unlock member function once for each call to Lock.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.