mirror of
https://github.com/changkun/modern-cpp-tutorial.git
synced 2025-12-17 12:44:40 +03:00
23 lines
339 B
C++
23 lines
339 B
C++
#include <thread>
|
|
#include <iostream>
|
|
|
|
int main() {
|
|
int a = 0;
|
|
volatile int flag = 0;
|
|
|
|
std::thread t1([&]() {
|
|
while (flag != 1);
|
|
|
|
int b = a;
|
|
std::cout << "b = " << b << std::endl;
|
|
});
|
|
|
|
std::thread t2([&]() {
|
|
a = 5;
|
|
flag = 1;
|
|
});
|
|
|
|
t1.join();
|
|
t2.join();
|
|
return 0;
|
|
} |