| title | CComMultiThreadModelNoCS Class | |||||||
|---|---|---|---|---|---|---|---|---|
| ms.date | 11/04/2016 | |||||||
| f1_keywords |
|
|||||||
| helpviewer_keywords |
|
|||||||
| ms.assetid | 2b3f7a45-fd72-452c-aaf3-ccdaa621c821 |
CComMultiThreadModelNoCS provides thread-safe methods for incrementing and decrementing the value of a variable, without critical section locking or unlocking functionality.
class CComMultiThreadModelNoCS
| Name | Description |
|---|---|
| CComMultiThreadModelNoCS::AutoCriticalSection | References class CComFakeCriticalSection. |
| CComMultiThreadModelNoCS::CriticalSection | References class CComFakeCriticalSection. |
| CComMultiThreadModelNoCS::ThreadModelNoCS | References class CComMultiThreadModelNoCS. |
| Name | Description |
|---|---|
| CComMultiThreadModelNoCS::Decrement | (Static) Decrements the value of the specified variable in a thread-safe manner. |
| CComMultiThreadModelNoCS::Increment | (Static) Increments the value of the specified variable in a thread-safe manner. |
CComMultiThreadModelNoCS is similar to CComMultiThreadModel in that it provides thread-safe methods for incrementing and decrementing a variable. However, when you reference a critical section class through CComMultiThreadModelNoCS, methods such as Lock and Unlock will do nothing.
Typically, you use CComMultiThreadModelNoCS through the ThreadModelNoCS typedef name. This typedef is defined in CComMultiThreadModelNoCS, CComMultiThreadModel, and CComSingleThreadModel.
Note
The global typedef names CComObjectThreadModel and CComGlobalsThreadModel do not reference CComMultiThreadModelNoCS.
In addition to ThreadModelNoCS, CComMultiThreadModelNoCS defines AutoCriticalSection and CriticalSection. These latter two typedef names reference CComFakeCriticalSection, which provides empty methods associated with obtaining and releasing a critical section.
Header: atlbase.h
When using CComMultiThreadModelNoCS, the typedef name AutoCriticalSection references class CComFakeCriticalSection.
typedef CComFakeCriticalSection AutoCriticalSection;
Because CComFakeCriticalSection does not provide a critical section, its methods do nothing.
CComMultiThreadModel and CComSingleThreadModel also contain definitions for AutoCriticalSection. The following table shows the relationship between the threading model class and the critical section class referenced by AutoCriticalSection:
| Class defined in | Class referenced |
|---|---|
CComMultiThreadModelNoCS |
CComFakeCriticalSection |
CComMultiThreadModel |
CComAutoCriticalSection |
CComSingleThreadModel |
CComFakeCriticalSection |
In addition to AutoCriticalSection, you can use the typedef name CriticalSection. You should not specify AutoCriticalSection in global objects or static class members if you want to eliminate the CRT startup code.
See CComMultiThreadModel::AutoCriticalSection.
When using CComMultiThreadModelNoCS, the typedef name CriticalSection references class CComFakeCriticalSection.
typedef CComFakeCriticalSection CriticalSection;
Because CComFakeCriticalSection does not provide a critical section, its methods do nothing.
CComMultiThreadModel and CComSingleThreadModel also contain definitions for CriticalSection. The following table shows the relationship between the threading model class and the critical section class referenced by CriticalSection:
| Class defined in | Class referenced |
|---|---|
CComMultiThreadModelNoCS |
CComFakeCriticalSection |
CComMultiThreadModel |
CComCriticalSection |
CComSingleThreadModel |
CComFakeCriticalSection |
In addition to CriticalSection, you can use the typedef name AutoCriticalSection. You should not specify AutoCriticalSection in global objects or static class members if you want to eliminate the CRT startup code.
See CComMultiThreadModel::AutoCriticalSection.
This static function calls the Win32 function InterlockedDecrement, which decrements the value of the variable pointed to by p.
static ULONG WINAPI Decrement(LPLONG p) throw();
p
[in] Pointer to the variable to be decremented.
If the result of the decrement is 0, then Decrement returns 0. If the result of the decrement is nonzero, the return value is also nonzero but may not equal the result of the decrement.
InterlockedDecrement prevents more than one thread from simultaneously using this variable.
This static function calls the Win32 function InterlockedIncrement, which increments the value of the variable pointed to by p.
static ULONG WINAPI Increment(LPLONG p) throw();
p
[in] Pointer to the variable to be incremented.
If the result of the increment is 0, then Increment returns 0. If the result of the increment is nonzero, the return value is also nonzero but may not equal the result of the increment.
InterlockedIncrement prevents more than one thread from simultaneously using this variable.
When using CComMultiThreadModelNoCS, the typedef name ThreadModelNoCS simply references CComMultiThreadModelNoCS.
typedef CComMultiThreadModelNoCS ThreadModelNoCS;
CComMultiThreadModel and CComSingleThreadModel also contain definitions for ThreadModelNoCS. The following table shows the relationship between the threading model class and the class referenced by ThreadModelNoCS:
| Class defined in | Class referenced |
|---|---|
CComMultiThreadModelNoCS |
CComMultiThreadModelNoCS |
CComMultiThreadModel |
CComMultiThreadModelNoCS |
CComSingleThreadModel |
CComSingleThreadModel |
Note that the definition of ThreadModelNoCS in CComMultiThreadModelNoCS provides symmetry with CComMultiThreadModel and CComSingleThreadModel. For example, suppose the sample code in CComMultiThreadModel::AutoCriticalSection declared the following typedef:
[!code-cppNVC_ATL_COM#37]
Regardless of the class specified for ThreadModel (such as CComMultiThreadModelNoCS), _ThreadModel resolves accordingly.