C++ std::scoped_lock (C++ 17)


Example

std::scoped_lock provides RAII style semantics for owning one more mutexes, combined with the lock avoidance algorithms used by std::lock. When std::scoped_lock is destroyed, mutexes are released in the reverse order from which they where acquired.

{
    std::scoped_lock lock{_mutex1,_mutex2};
    //do something
}