| Home | Libraries | People | FAQ | More

## Class try_read_write_mutex

boost::try_read_write_mutex —

The try_read_write_mutex class is a model of the TryReadWriteMutex concept.

## Synopsis

    class try_read_write_mutex : private boost::noncopyable   // Exposition only
    {
    public:
      // types
      typedef implementation-defined scoped_read_write_lock;
      typedef implementation-defined scoped_try_read_write_lock;
      typedef implementation-defined scoped_read_lock;
      typedef implementation-defined scoped_try_read_lock;
      typedef implementation-defined scoped_write_lock;
      typedef implementation-defined scoped_try_write_lock;

      // construct/copy/destruct
      try_read_write_mutex(boost::read_write_scheduling_policy);
      ~try_read_write_mutex();
    };

## Description

The try_read_write_mutex class is a model of the TryReadWriteMutex concept. It should be used to synchronize access to shared resources using Unspecified locking mechanics.

For classes that model related mutex concepts, see read_write_mutex and timed_read_write_mutex.

The try_read_write_mutex class supplies the following typedefs, which model the specified locking strategies:

Lock Name | Lock Concept
--- | ---
scoped_read_write_lock | ScopedReadWriteLock
scoped_try_read_write_lock | ScopedTryReadWriteLock
scoped_read_lock | ScopedLock
scoped_try_read_lock | ScopedTryLock
scoped_write_lock | ScopedLock
scoped_try_write_lock | ScopedTryLock

The try_read_write_mutex class uses an Unspecified locking strategy, so attempts to recursively lock a try_read_write_mutex object or attempts to unlock one by threads that don't own a lock on it result in undefined behavior. This strategy allows implementations to be as efficient as possible on any given platform. It is, however, recommended that implementations include debugging support to detect misuse when `NDEBUG` is not defined.

Like all read/write mutex models in , try_read_write_mutex has two types of scheduling policies, an inter-class sheduling policy between threads trying to obtain different types of locks and an intra-class sheduling policy between threads trying to obtain the same type of lock. The try_read_write_mutex class allows the programmer to choose what inter-class sheduling policy will be used; however, like all read/write mutex models, try_read_write_mutex leaves the intra-class sheduling policy as Unspecified.

### Note

Self-deadlock is virtually guaranteed if a thread tries to lock the same try_read_write_mutex multiple times unless all locks are read-locks (but see below)

### `try_read_write_mutex` construct/copy/destruct

1.     try_read_write_mutex(boost::read_write_scheduling_policy count);

   Effects: Constructs a try_read_write_mutex object.
   Postconditions: `*this` is in an unlocked state.

2.     ~try_read_write_mutex();

   Effects: Destroys a try_read_write_mutex object.
   Requires: `*this` is in an unlocked state.
   Notes: Danger: Destruction of a locked mutex is a serious programming error resulting in undefined behavior such as a program crash.

| Copyright © 2001-2003 William E. Kempf