I\'m wondering if it\'s possible to lock multiple mutexes at the same time, like:
Mutex1.Lock(); { Mutex2.Lock(); { // Code locked by m
C++17 also provides scoped_lock for the specific purpose of locking multiple mutexes that prevents deadlock in a RAII style, similar to lock_guard.
scoped_lock
lock_guard
#include std::mutex mtx1, mtx2; void foo() { std::scoped_lock lck{mtx1, mtx2}; // proceed }