CComCriticalSection

class CComCriticalSection

CComCriticalSection provides methods for obtaining and releasing ownership of a critical section object. CComCriticalSection is similar to class CComAutoCriticalSection, except that you must explicitly initialize and release the critical section object.

Typically, you use CComCriticalSection through the typedef name, CriticalSection. This name references CComCriticalSection when CComMultiThreadModel is being used.

#include <atlbase.h>

See Also CComFakeCriticalSection


CComCriticalSection Class Members

Methods
InitCreates and initializes a critical section object.
LockObtains ownership of a critical section object.
TermReleases system resources used by a critical section object.
UnlockReleases ownership of a critical section object.
Data Members
m_secA CRITICAL_SECTION object.

CComCriticalSection Overview


Methods


CComCriticalSection::Init

void Init( );

Remarks

Calls the Win32 function InitializeCriticalSection, which initializes the critical section object contained in the m_sec data member.

CComCriticalSection Overview | Class Members

See Also InitializeCriticalSection in the Win32 SDK


CComCriticalSection::Lock

void Lock( );

Remarks

Calls the Win32 function EnterCriticalSection, which waits until the thread can take ownership of the critical section object contained in the m_sec data member. The critical section object must first be initialized with a call to the Init method. When the protected code has finished executing, the thread must call Unlock to release ownership of the critical section.

CComCriticalSection Overview | Class Members

See Also EnterCriticalSection in the Win32 SDK


CComCriticalSection::Term

void Term( );

Remarks

Calls the Win32 function DeleteCriticalSection, which releases all resources used by the critical section object contained in the m_sec data member. Once Term has been called, the critical section can no longer be used for synchronization.

CComCriticalSection Overview | Class Members

See Also DeleteCriticalSection in the Win32 SDK


CComCriticalSection::Unlock

void Unlock( );

Remarks

Calls the Win32 function LeaveCriticalSection, which releases ownership of the critical section object contained in the m_sec data member. To first obtain ownership, the thread must call the Lock method. Each call to Lock requires a corresponding call to Unlock to release ownership of the critical section.

CComCriticalSection Overview | Class Members

See Also LeaveCriticalSection in the Win32 SDK


Data Members


CComCriticalSection::m_sec

CRITICAL_SECTION m_sec;

Remarks

Contains a critical section object that is used by all CComCriticalSection methods.

CComCriticalSection Overview | Class Members

See Also CComCriticalSection::Lock, CComCriticalSection::Unlock, CComCriticalSection::Init, CComCriticalSection::Term