33 Thread support library [thread]
namespace std {
template <class... MutexTypes>
class scoped_lock {
public:
using mutex_type = Mutex;
explicit scoped_lock(MutexTypes&... m);
explicit scoped_lock(MutexTypes&... m, adopt_lock_t);
~scoped_lock();
scoped_lock(const scoped_lock&) = delete;
scoped_lock& operator=(const scoped_lock&) = delete;
private:
tuple<MutexTypes&...> pm; };
template<class... MutexTypes>
scoped_lock(scoped_lock<MutexTypes...>) -> scoped_lock<MutexTypes...>;
}
An object of type
scoped_lock controls the ownership of lockable objects
within a scope
. A
scoped_lock object maintains ownership of lockable
objects throughout the
scoped_lock object's lifetime (
[basic.life])
. The behavior of a program is undefined if the lockable objects referenced by
pm do not exist for the entire lifetime of the
scoped_lock
object
. explicit scoped_lock(MutexTypes&... m);
Requires: If a
MutexTypes type is not a recursive mutex,
the calling thread does not own the corresponding mutex element of
m. Effects: Initializes
pm with
tie(m...). Then if
sizeof...(MutexTypes) is
0, no effects
. Otherwise if
sizeof...(MutexTypes) is
1, then
m.lock(). explicit scoped_lock(MutexTypes&... m, adopt_lock_t);
Requires: The calling thread owns all the mutexes in
m. Effects: Initializes
pm with
tie(m...). ~scoped_lock();
Effects: For all
i in
[0, sizeof...(MutexTypes)),
get<i>(pm).unlock().