Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.

Class recursive_mutex

boost::recursive_mutex —

The recursive_mutex class is a model of the Mutex concept.


class recursive_mutex : private boost::noncopyable   // Exposition only
// types
typedef implementation-defined scoped_lock;

// construct/copy/destruct


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

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

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

The recursive_mutex class supplies the following typedef, which models the specified locking strategy:

Table12.12.Supported Lock Types

Lock Name Lock Concept
scoped_lock ScopedLock

The recursive_mutex class uses a Recursive locking strategy, so attempts to recursively lock a recursive_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_mutex leaves the scheduling policy as Unspecified. Programmers should make no assumptions about the order in which waiting threads acquire a lock.

recursive_mutex construct/copy/destruct

  1. recursive_mutex();

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

  2. ~recursive_mutex();

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