Files
2025-10-25 03:02:53 +03:00

3.6 KiB

[thread.lock.scoped]

32 Concurrency support library [thread]

32.6 Mutual exclusion [thread.mutex]

32.6.5 Locks [thread.lock]

32.6.5.3 Class template scoped_lock [thread.lock.scoped]

🔗

namespace std {template<class... MutexTypes>class scoped_lock {public:using mutex_type = see below; // Only if sizeof...(MutexTypes) == 1 is trueexplicit scoped_lock(MutexTypes&... m); explicit scoped_lock(adopt_lock_t, MutexTypes&... m); ~scoped_lock();

scoped_lock(const scoped_lock&) = delete; scoped_lock& operator=(const scoped_lock&) = delete; private: tuple<MutexTypes&...> pm; // exposition only};}

1

#

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.

The behavior of a program is undefined if the lockable objects referenced bypm do not exist for the entire lifetime of the scoped_lock object.

🔗

explicit scoped_lock(MutexTypes&... m);

2

#

Effects: Initializes pm with tie(m...).

Then if sizeof...(MutexTypes) is 0, no effects.

Otherwise if sizeof...(MutexTypes) is 1, then m.lock().

Otherwise, lock(m...).

🔗

explicit scoped_lock(adopt_lock_t, MutexTypes&... m);

3

#

Preconditions: The calling thread holds a non-shared lock on each element of m.

4

#

Effects: Initializes pm with tie(m...).

5

#

Throws: Nothing.

🔗

~scoped_lock();

6

#

Effects: For all i in [0, sizeof...(MutexTypes)),get(pm).unlock().