Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <mutex>
#include <thread>
std::mutex mtx;
int value = 0;
void add() {
std::unique_lock<std::mutex> lock(mtx);
value++;
}
int main() {
std::thread t1(add);
std::thread t2(add);
t1.join();
t2.join();
std::cout << value;
return 0;
}Coding works best on desktop or with an external keyboard.