Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Threads Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

RWTMonitor<Mutex>

Module:  Threads   Package:  Synchronization


Base Class

Local Index

Members

Header File

#include <rw/sync/RWTMonitor.h> 

Description

Subclassing from RWTMonitor<Mutex> provides a convenient way to synchronize the member functions used to access the data or resources encapsulated by a class. RWTMonitor<Mutex> supplies the mutual exclusion and guard mechanisms for synchronizing member functions; any functions that must be synchronized use the supplied guard type to lock and unlock the monitor upon entry and exit from the function.

One advantage of using RWTMonitor<Mutex> as a base-class instead of directly inheriting from or including some synchronization class, is the monitor() member function. If you were to use your own mutex member for synchronization, you would have to cast away the const-ness of this in const member functions before acquiring or releasing the mutex. The monitor() function eliminates this inconvenience by always returning a non-const instance of the monitor. The reference returned by monitor() can be used to initialize any of public guard types defined by the RWTMonitor<Mutex> class.

Example

Public Typedef

typedef Mutex   MutexType;

Protected Typedefs

typedef RWTLockGuard< RWTMonitor< Mutex > >     LockGuard;
typedef RWTUnlockGuard< RWTMonitor< Mutex > >   UnlockGuard;
typedef RWTTryLockGuard< RWTMonitor< Mutex > >  TryLockGuard;

Protected Constructors

RWTMonitor();
RWTMonitor(RWStaticCtor);
RWTMonitor(const RWTMonitor<Mutex>& second);

Protected Destructor

~RWTMonitor();

Protected Member Operator

RWTMonitor<Mutex>&
operator=(const RWTMonitor<Mutex>&);

Protected Member Functions

void
acquire();
bool
isAcquired() const;

NOTE -- This function is primarily intended for use in precondition assertions, and is only available when you build the debug version of the module.
RWTMonitor<Mutex>&
monitor() const;
Mutex&
mutex();
void
release();
bool
tryAcquire():

See Also

RWMutexLock, RWTLockGuard<Resource>, RWTUnlockGuard<Resource>, RWTTryLockGuard<Resource>



Previous fileTop of DocumentContentsIndex pageNext file

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