CComAutoCriticalSection

class CComAutoCriticalSection

CComAutoCriticalSection provides methods for obtaining and releasing ownership of a critical section object. CComAutoCriticalSection is similar to class CComCriticalSection, except CComAutoCriticalSection automatically initializes critical section objects in the constructor.

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

You should not use CComAutoCriticalSection in global objects or static class members if you want to eliminate the CRT startup code. In this case, use CComCriticalSection.

#include <atlbase.h>

See Also CComFakeCriticalSection


CComAutoCriticalSection Class Members

Methods
CComAutoCriticalSectionConstructor.
LockObtains ownership of a critical section object.
UnlockReleases ownership of a critical section object.
Data Members
m_secA CRITICAL_SECTION object.

CComAutoCriticalSection Overview


Methods


CComAutoCriticalSection::CComAutoCriticalSection

void CComAutoCriticalSection( );

Remarks

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

The destructor calls DeleteCriticalSection, which releases all system resources used by the critical section object.

CComAutoCriticalSection Overview | Class Members

See Also InitializeCriticalSection and DeleteCriticalSection in the Win32 SDK


CComAutoCriticalSection::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. When the protected code has finished executing, the thread must call Unlock to release ownership of the critical section.

CComAutoCriticalSection Overview | Class Members

See Also EnterCriticalSection in the Win32 SDK


CComAutoCriticalSection::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 then requires a corresponding call to Unlock to release ownership of the critical section.

CComAutoCriticalSection Overview | Class Members

See Also LeaveCriticalSection in the Win32 SDK


Data Members


CComAutoCriticalSection::m_sec

CRITICAL_SECTION m_sec;

Remarks

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

CComAutoCriticalSection Overview | Class Members

See Also CComAutoCriticalSection::CComAutoCriticalSection, CComAutoCriticalSection::Lock, CComAutoCriticalSection::Unlock