Using the same mutex for unique_lock and scoped_lock

1k views Asked by At

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();
0

There are 0 answers