Mercer
Mercer

Reputation: 147

Using the same mutex for unique_lock and scoped_lock

Is it appropriate to use both a unique_lock and a scoped_lock with the same mutex? To allow for use of cv.wait and optional unlocking while also providing scope-bound safety.

For example;

std::mutex mut;

//thread:

std::condition_variable cv;

std::unique_lock lock(mut);
cv.wait(lock);
std::scoped_lock scopeLock(std::adopt_lock, mut);
lock.release();
//tasks

scopeLock.~scoped_lock();

Upvotes: 2

Views: 1122

Answers (0)

Related Questions