Boost C++ Libraries

...one 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 to view this page for the latest version.
PrevUpHomeNext

Class mutex

boost::signals2::mutex — A header-only mutex which implements the Lockable concept of Boost.Thread.

Synopsis

// In header: <boost/signals2/mutex.hpp>


class mutex {
public:
  void lock();
  bool try_lock();
  void unlock();
};

Description

The mutex class implements the Lockable concept of Boost.Thread, and is the default Mutex template parameter type for signals. If boost has detected thread support in your compiler, the mutex class will map to a CRITICAL_SECTION on Windows or a pthread_mutex on POSIX. If thread support is not detected, mutex will behave similarly to a dummy_mutex. The header file boost/config.hpp defines the macro BOOST_HAS_THREADS when boost detects threading support. The user may globally disable thread support in boost by defining BOOST_DISABLE_THREADS before any boost header files are included.

If you are already using the Boost.Thread library, you may prefer to use its boost::mutex class instead as the mutex type for your signals.

You may wish to use a thread-unsafe signal, if the signal is only used by a single thread. In that case, you may prefer to use the signals2::dummy_mutex class as the Mutex template type for your signal.

void lock();

Locks the mutex.

bool try_lock();

Makes a non-blocking attempt to lock the mutex.

Returns:

true on success.

void unlock();

Unlocks the mutex.


PrevUpHomeNext