Class Library Reference Manual
The Mutex package provides a way to synchronize access to user-defined
objects. It consists of a single class,
, that manages the creation, locking and unlocking of
Construction of a
object creates a recursive mutex that users can lock and unlock using
the appropriate member functions or parameterized manipulators. A
recursive mutex is a mutex that can be locked many
times by the same thread without causing the thread to enter a deadlock
state. To completely unlock this kind of mutex, the thread must unlock
the mutex the same number of times that the thread locked the mutex.
For more information see the Guide to DECthreads manual.
User-defined objects are not automatically thread safe. Users must
supply synchronization for such objects if they are shared between
Provides a means whereby users can synchronize access to user-defined
The synchronization process consists of locking and unlocking
objects associated with user-defined objects. HP recommends that users
object for each user-defined object that needs to be synchronized
between threads. Users are then responsible for locking and unlocking
object to coordinate access to the associated object.
To do the locking and unlocking, you can use the
member functions (see Example). Alternatively, if a user-defined object
is derived from the
classes, you can use the
parameterized manipulators, where the parameter is the
object (see the Global Declarations section in Chapter 4).
Constructors and Destructors
object, in effect creating but not locking a recursive mutex.
Locks a recursive mutex. If the mutex is locked by another thread, the
current thread is blocked until the mutex becomes available.
Unlocks a recursive mutex.
Immediately returns to the caller a value of 0 if the mutex is already
locked by another thread. Otherwise, this function locks the mutex and
returns a value of 1.
string1 = "Hello, ";
string1 += "how are you?";
cout << string1;
This example synchronizes a sequence of operations on a
object, using the