CComSingleThreadModel Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

This class provides methods for incrementing and decrementing the value of a variable.

class CComSingleThreadModel

Public Typedefs

NameDescription
CComSingleThreadModel::AutoCriticalSectionReferences class CComFakeCriticalSection.
CComSingleThreadModel::CriticalSectionReferences class CComFakeCriticalSection.
CComSingleThreadModel::ThreadModelNoCSReferences CComSingleThreadModel.

Public Methods

NameDescription
CComSingleThreadModel::DecrementDecrements the value of the specified variable. This implementation is not thread-safe.
CComSingleThreadModel::IncrementIncrements the value of the specified variable. This implementation is not thread-safe.

CComSingleThreadModel provides methods for incrementing and decrementing the value of a variable. Unlike CComMultiThreadModel and CComMultiThreadModelNoCS, these methods are not thread-safe.

Typically, you use CComSingleThreadModel through one of two typedef names, either CComObjectThreadModel or CComGlobalsThreadModel. The class referenced by each typedef depends on the threading model used, as shown in the following table:

typedefSingle threading modelApartment threading modelFree threading model
CComObjectThreadModelSSM
CComGlobalsThreadModelSMM

S= CComSingleThreadModel; M= CComMultiThreadModel

CComSingleThreadModel itself defines three typedef names. ThreadModelNoCS references CComSingleThreadModel. AutoCriticalSection and CriticalSection reference class CComFakeCriticalSection, which provides empty methods associated with obtaining and releasing ownership of a critical section.

Header: atlbase.h

When using CComSingleThreadModel, the typedef name AutoCriticalSection references class CComFakeCriticalSection.

typedef CComFakeCriticalSection AutoCriticalSection;

Remarks

Because CComFakeCriticalSection does not provide a critical section, its methods do nothing.

CComMultiThreadModel and CComMultiThreadModelNoCS 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 inClass referenced
CComSingleThreadModelCComFakeCriticalSection
CComMultiThreadModelCComAutoCriticalSection
CComMultiThreadModelNoCSCComFakeCriticalSection

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.

Example

See CComMultiThreadModel::AutoCriticalSection.

When using CComSingleThreadModel, the typedef name CriticalSection references class CComFakeCriticalSection.

typedef CComFakeCriticalSection CriticalSection;

Remarks

Because CComFakeCriticalSection does not provide a critical section, its methods do nothing.

CComMultiThreadModel and CComMultiThreadModelNoCS 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 inClass referenced
CComSingleThreadModelCComFakeCriticalSection
CComMultiThreadModelCComCriticalSection
CComMultiThreadModelNoCSCComFakeCriticalSection

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.

Example

See CComMultiThreadModel::AutoCriticalSection.

This static function decrements the value of the variable pointed to by p.

static ULONG WINAPI Decrement(LPLONG p) throw ();

Parameters

p
[in] Pointer to the variable to be decremented.

Return Value

The result of the decrement.

This static function decrements the value of the variable pointed to by p.

static ULONG WINAPI Increment(LPLONG p) throw ();

Parameters

p
[in] Pointer to the variable to be incremented.

Return Value

The result of the increment.

When using CComSingleThreadModel, the typedef name ThreadModelNoCS simply references CComSingleThreadModel.

typedef CComSingleThreadModel ThreadModelNoCS;

Remarks

CComMultiThreadModel and CComMultiThreadModelNoCS contain definitions for ThreadModelNoCS. The following table shows the relationship between the threading model class and the class referenced by ThreadModelNoCS:

Class defined inClass referenced
CComSingleThreadModelCComSingleThreadModel
CComMultiThreadModelCComMultiThreadModelNoCS
CComMultiThreadModelNoCSCComMultiThreadModelNoCS

Example

See CComMultiThreadModel::AutoCriticalSection.

Class Overview

Show: