description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CComCriticalSection Class |
CComCriticalSection Class |
11/04/2016 |
|
|
44e1edd2-90be-4bfe-9739-58e8b419e7d1 |
This class provides methods for obtaining and releasing ownership of a critical section object.
class CComCriticalSection
Name | Description |
---|---|
CComCriticalSection::CComCriticalSection | The constructor. |
Name | Description |
---|---|
CComCriticalSection::Init | Creates and initializes a critical section object. |
CComCriticalSection::Lock | Obtains ownership of the critical section object. |
CComCriticalSection::Term | Releases system resources used by the critical section object. |
CComCriticalSection::Unlock | Releases ownership of the critical section object. |
Name | Description |
---|---|
CComCriticalSection::m_sec | A CRITICAL_SECTION object. |
CComCriticalSection
is similar to class CComAutoCriticalSection, except that you must explicitly initialize and release the critical section.
Typically, you use CComCriticalSection
through the typedef
name CriticalSection. This name references CComCriticalSection
when CComMultiThreadModel is being used.
See CComCritSecLock Class for a safer way to use this class than calling Lock
and Unlock
directly.
Header: atlcore.h
The constructor.
CComCriticalSection() throw();
Sets the m_sec data member to NULL.
Calls the Win32 function InitializeCriticalSection, which initializes the critical section object contained in the m_sec data member.
HRESULT Init() throw();
Returns S_OK on success, E_OUTOFMEMORY or E_FAIL on failure.
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.
HRESULT Lock() throw();
Returns S_OK on success, E_OUTOFMEMORY or E_FAIL on failure.
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.
Contains a critical section object that is used by all CComCriticalSection
methods.
CRITICAL_SECTION m_sec;
Calls the Win32 function DeleteCriticalSection, which releases all resources used by the critical section object contained in the m_sec data member.
HRESULT Term() throw();
Returns S_OK.
Once Term
has been called, the critical section can no longer be used for synchronization.
Calls the Win32 function LeaveCriticalSection, which releases ownership of the critical section object contained in the m_sec data member.
HRESULT Unlock() throw();
Returns S_OK.
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.
CComFakeCriticalSection Class
Class Overview
CComCritSecLock Class