book: revision of ch07 & finish atomics

Update #2
This commit is contained in:
Changkun Ou
2019-07-19 10:59:01 +02:00
parent fdb34b80e5
commit 677f74b691
12 changed files with 327 additions and 81 deletions

View File

@@ -0,0 +1,23 @@
#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;
}