Quiz · Multithreading: An Overview · lesson 6 of 10
Quiz — two mutexes in opposite order
What can happen if two threads call lock_both(a, b) and lock_both(b, a) at once?
#include <mutex>
std::mutex a;
std::mutex b;
void lock_both(std::mutex& first, std::mutex& second) {
std::lock_guard<std::mutex> g1(first);
std::lock_guard<std::mutex> g2(second);
}