rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWCriticalSection Class Reference
[Synchronization]

Provides mutual exclusion for a critical section of code in which only one thread should execute at a time. More...

#include <rw/sync/RWCriticalSection.h>

Inheritance diagram for RWCriticalSection:
RWSynchObject

List of all members.

Public Types

typedef RWTLockGuard
< RWCriticalSection
LockGuard
typedef RWTLockGuard
< RWCriticalSection
ReadLockGuard
typedef RWTLockGuard
< RWCriticalSection
WriteLockGuard
typedef RWTUnlockGuard
< RWCriticalSection
UnlockGuard
typedef RWTUnlockGuard
< RWCriticalSection
ReadUnlockGuard
typedef RWTUnlockGuard
< RWCriticalSection
WriteUnlockGuard

Public Member Functions

 RWCriticalSection (RWStaticCtor)
 RWCriticalSection (RWCancellationState state=0)
 ~RWCriticalSection ()
RWCriticalSectionRepgetCriticalSectionRep () const
void acquire ()
void release ()
void acquireRead ()
void acquireWrite ()

Private Member Functions

 RWCriticalSection (const RWCriticalSection &)
RWCriticalSectionoperator= (const RWCriticalSection &)

Related Functions

(Note that these are not member functions.)



typedef RWMutexLock RWCriticalSectionRep
typedef RWMutexType RWCriticalSectionRep

Detailed Description

An RWCriticalSection object is used to provide mutual exclusion for a critical section of code, i.e. code in which only one thread should execute at a time. This lock operates in a manner that is identical to RWMutexLock except that on certain platforms, for example Win32, it may yield superior performance when there is minimal contention for the lock.

Examples

 #include <rw/sync/RWCriticalSection.h>
 
 void foo ()
 {
     static RWCriticalSection outputCritsec(RW_STATIC_CTOR);
 
     // ...
 
     int i;
 
     // ...
 
     // Protect output from multiple threads
     // using cout at the same time:
     outputCritsec.acquire ();
     std::cout << "The value of i is " << i << std::endl;
     outputCritsec.release ();
 
     // Same thing, this time using a guard:
     {
         RWCriticalSection::LockGuard lock (outputCritsec);
         std::cout << "The value of i is " << i << std::endl;
     }
 }
See also:
RWMutexLock

Member Typedef Documentation

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.

Predefined type for compatible guard.


Constructor & Destructor Documentation

RWCriticalSection::RWCriticalSection ( RWStaticCtor   )  [inline]

Constructs a static instance, but does no direct initialization. The RWCriticalSection is initialized on first use.

This constructor must be used only for static instances. Use of this constructor with automatically or dynamically allocated instances produces errors or other unpredictable behavior.

Static instances are zero initialized, which results in an RWCriticalSection with cancellation state of RW_CANCELLATION_DISABLED.

RWCriticalSection::RWCriticalSection ( RWCancellationState  state = 0  )  [inline]

Creates and initializes the critical section. Possible exceptions include RWTHRInternalError.

RWCriticalSection::~RWCriticalSection (  )  [inline]

Default destructor.

RWCriticalSection::RWCriticalSection ( const RWCriticalSection  )  [private]

Copy construction prohibited.


Member Function Documentation

void RWCriticalSection::acquire ( void   )  [inline]

Blocks until the critical section is available. Possible exceptions include RWCancellation and RWTHRInternalError.

In single-threaded builds, this method returns immediately. If the section is unavailable, a debug assertion will occur, or an RWTHRInternalError will be thrown.

void RWCriticalSection::acquireRead (  )  [inline]

Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.

void RWCriticalSection::acquireWrite (  )  [inline]

Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.

RWCriticalSectionRep * RWCriticalSection::getCriticalSectionRep (  )  const [inline]

Provides access to the underlying platform-specific critical section implementation.

RWCriticalSection& RWCriticalSection::operator= ( const RWCriticalSection  )  [private]

Assignment prohibited.

void RWCriticalSection::release ( void   )  [inline]

Releases the critical section. Possible exceptions include RWTHRInternalError.


Friends And Related Function Documentation

typedef RWMutexType RWCriticalSectionRep [related]

Typedef for the internal critical section.

Condition:
This type is used for build configurations based on Win32 threads.
typedef RWMutexLock RWCriticalSectionRep [related]

Typedef for the internal critical section.

Condition:
This type is used for build configurations based on POSIX or Solaris threads.
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.