Quiz · Multithreading: An Overview · lesson 7 of 12
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);
}Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.