Skip to content
Quiz · Multithreading: An Overview · lesson 5 of 10

Quiz — where the mutex is released

Where, if anywhere, does the call add(-1) unlock the mutex m?

C++
#include <mutex>

std::mutex m;
int total = 0;

void add(int x) {
    std::lock_guard<std::mutex> guard(m);
    if (x < 0) {
        return;
    }
    total += x;
}