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
Methods | |
Init | Creates and initializes a critical section object. |
Lock | Obtains ownership of a critical section object. |
Term | Releases system resources used by a critical section object. |
Unlock | Releases ownership of a critical section object. |
Data Members | |
m_sec | A CRITICAL_SECTION object. |
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
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
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
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
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