| Home | Libraries | People | FAQ | More

## Class recursive_try_mutex

boost::recursive_try_mutex —

The recursive_try_mutex class is a model of the TryMutex concept.

## Synopsis

    class recursive_try_mutex : private boost::noncopyable   // Exposition only
    {
    public:
      // types
      typedef implementation-defined scoped_lock;
      typedef implementation-defined scoped_try_lock;

      // construct/copy/destruct
      recursive_try_mutex();
      ~recursive_try_mutex();
    };

## Description

The recursive_try_mutex class is a model of the TryMutex concept. It should be used to synchronize access to shared resources using Recursive locking mechanics.

For classes that model related mutex concepts, see recursive_mutex and recursive_timed_mutex.

For Unspecified locking mechanics, see mutex, try_mutex, and timed_mutex.

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

Table 12.13. Supported Lock Types

Lock Name | Lock Concept
--- | ---
scoped_lock | ScopedLock
scoped_try_lock | ScopedTryLock

The recursive_try_mutex class uses a Recursive locking strategy, so attempts to recursively lock a recursive_try_mutex object succeed and an internal "lock count" is maintained. Attempts to unlock a recursive_mutex object by threads that don't own a lock on it result in undefined behavior.

Like all mutex models in Boost.Threads, recursive_try_mutex leaves the scheduling policy as Unspecified. Programmers should make no assumptions about the order in which waiting threads acquire a lock.

### `recursive_try_mutex` construct/copy/destruct

1.     recursive_try_mutex();

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

2.     ~recursive_try_mutex();

   Effects: Destroys a recursive_try_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