![]() |
Home | Libraries | People | FAQ | More |
// #include <boost/thread/locks.hpp> // #include <boost/thread/lock_guard.hpp> namespace boost { template<typename Lockable> class lock_guard #if ! defined BOOST_THREAD_NO_MAKE_LOCK_GUARD template <typename Lockable> lock_guard<Lockable> make_lock_guard(Lockable& mtx); // EXTENSION template <typename Lockable> lock_guard<Lockable> make_lock_guard(Lockable& mtx, adopt_lock_t); // EXTENSION #endif }
// #include <boost/thread/locks.hpp> // #include <boost/thread/lock_guard.hpp> template<typename Lockable> class lock_guard { public: explicit lock_guard(Lockable& m_); lock_guard(Lockable& m_,boost::adopt_lock_t); ~lock_guard(); };
boost::lock_guard
is very simple: on
construction it acquires ownership of the implementation of the Lockable
concept supplied as the
constructor parameter. On destruction, the ownership is released. This
provides simple RAII-style locking of a Lockable
object, to facilitate
exception-safe locking and unlocking. In addition, the lock_guard(Lockable &
m,boost::adopt_lock_t)
constructor allows the boost::lock_guard
object to take ownership
of a lock already held by the current thread.
The current thread owns a lock on m
equivalent to one obtained by a call to m.lock()
.
Stores a reference to m
.
Takes ownership of the lock state of m
.
Nothing.
Invokes m.unlock()
on the Lockable
object passed
to the constructor.
Nothing.
template <typename Lockable> lock_guard<Lockable> make_lock_guard(Lockable& m); // EXTENSION
a lock_guard as if initialized with {m}
.
Any exception thrown by the call to m.lock()
.
template <typename Lockable> lock_guard<Lockable> make_lock_guard(Lockable& m, adopt_lock_t); // EXTENSION
a lock_guard as if initialized with {m, adopt_lock}
.
Any exception thrown by the call to m.lock()
.