
RWCriticalSectionRWSynchObject
| LockGuard ReadLockGuard |
ReadUnlockGuard RWCriticalSectionRep |
UnlockGuard WriteLockGuard |
WriteUnlockGuard |
#include <rw/sync/RWCriticalSection.h>
An RWCriticalSection 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 func()
{
RWCriticalSection outputCritsec;
int i;
// ...
// Protect output from multiple threads
// using cout at the same time:
outputCritsec.acquire();
cout << "The value of i is " << i << endl;
outputCritsec.release();
// Same thing, this time using a guard:
{
RWCriticalSection::LockGuard lock(outputCritsec);
cout << "The value of i is " << i << endl;
}
}
typedef RWMutexLockRep RWCriticalSectionRep;
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.
void acquire(void);
Blocks until the critical section is available. Possible exceptions include RWCancellation and RWTHRInternalError.
void acquireRead(void);
Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
void acquireWrite(void);
Calls acquire(). Provided for compatibility with Read/Write locks. Possible exceptions include RWCancellation and RWTHRInternalError.
RWCriticalSectionRep* getCriticalSectionRep(void) const;
Provides access to the underlying mechanism.
void release(void);
Releases the critical section. Possible exceptions include RWTHRInternalError.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.