Module: Threads Package: Synchronization
RWCriticalSection RWSynchObject
acquire() acquireRead() acquireWrite() getCriticalSectionRep() |
LockGuard operator ReadLockGuard ReadUnlockGuard |
release() RWCriticalSection() UnlockGuard WriteLockGuard |
WriteUnlockGuard |
#include <rw/sync/RWCriticalSection.h>
An RWCriticalSection object is used to provide mutual exclusion for a critical section of code (sections of code where only one thread should be executing 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.
#include <rw/sync/RWCriticalSection.h> void foo () { static RWCriticalSection outputCritsec; // ... 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; } }
typedef CRITICAL_SECTION RWCriticalSectionRep;
This is the internal critical section variable representation, RWCriticalSectionRep, for Windows systems.
typedef RWMutexLockRep RWCriticalSectionRep;
This is the internal critical section variable representation, RWCriticalSectionRep, for Unix systems.
typedef RWTLockGuard<RWCriticalSection> LockGuard; typedef RWTLockGuard<RWCriticalSection> ReadLockGuard; typedef RWTLockGuard<RWCriticalSection> WriteLockGuard; typedef RWTUnlockGuard<RWCriticalSection> UnlockGuard; typedef RWTUnlockGuard<RWCriticalSection> ReadUnlockGuard; typedef RWTUnlockGuard<RWCriticalSection> WriteUnlockGuard;
Predefined types for compatible guards.
RWCriticalSection(RWCancellationState
state=RW_CANCELLATION_DISABLED);
Creates and initializes the critical section. Possible exceptions include RWTHRInternalError.
RWCriticalSection(RWStaticCtor);
Constructs a static instance, but does not initialize the critical section. The RWCriticalSection will be initialized on first use.
void acquire();
Blocks until the critical section is available. Possible exceptions include RWCancellation and RWTHRInternalError.
In single-threaded builds, this method will return immediately. If the section is unavailable, a debug assertion will occur, or an RWTHRInternalError will be thrown.
void acquireRead();
Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
void acquireWrite();
Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
RWCriticalSectionRep* getCriticalSectionRep() const;
Provides access to the underlying mechanism.
void release();
Releases the critical section. Possible exceptions include RWTHRInternalError.
RWCriticalSection(const RWCriticalSection& second);
Copy construction prohibited.
RWCriticalSection& operator=(const RWCriticalSection& second);
Assignment prohibited.
© 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.