CComMultiThreadModelNoCS Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CComMultiThreadModelNoCS Class.

CComMultiThreadModelNoCS` provides thread-safe methods for incrementing and decrementing the value of a variable, without critical section locking or unlocking functionality.

class CComMultiThreadModelNoCS

Public Typedefs

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

Public Methods

NameDescription
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.

System_CAPS_ICON_note.jpg 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;

Remarks

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

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

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 calls the Win32 function InterlockedDecrement, which 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

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.

Remarks

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 ();

Parameters

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

Return Value

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.

Remarks

InterlockedIncrement prevents more than one thread from simultaneously using this variable.

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

typedef CComMultiThreadModelNoCS ThreadModelNoCS;

Remarks

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 inClass referenced
CComMultiThreadModelNoCSCComMultiThreadModelNoCS
CComMultiThreadModelCComMultiThreadModelNoCS
CComSingleThreadModelCComSingleThreadModel

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:

   typedef typename ThreadModel::ThreadModelNoCS _ThreadModel;

Regardless of the class specified for ThreadModel (such as CComMultiThreadModelNoCS), _ThreadModel resolves accordingly.

Example

See CComMultiThreadModel::AutoCriticalSection.

Class Overview

Show: