閱讀英文

共用方式為


CComMultiThreadModelNoCS Class

 

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.

Syntax

class CComMultiThreadModelNoCS

Members

Public Typedefs

Name Description
CComMultiThreadModelNoCS::AutoCriticalSection References class CComFakeCriticalSection.
CComMultiThreadModelNoCS::CriticalSection References class CComFakeCriticalSection.
CComMultiThreadModelNoCS::ThreadModelNoCS References class CComMultiThreadModelNoCS.

Public Methods

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.

Remarks

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.

注意

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.

Requirements

Header: atlbase.h

CComMultiThreadModelNoCS::AutoCriticalSection

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

Example

See CComMultiThreadModel::AutoCriticalSection.

CComMultiThreadModelNoCS::CriticalSection

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

Example

See CComMultiThreadModel::AutoCriticalSection.

CComMultiThreadModelNoCS::Decrement

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.

CComMultiThreadModelNoCS::Increment

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.

CComMultiThreadModelNoCS::ThreadModelNoCS

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 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:

   typedef typename ThreadModel::ThreadModelNoCS _ThreadModel;

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

Example

See CComMultiThreadModel::AutoCriticalSection.

See Also

Class Overview