1 Star 0 Fork 0

gitstr/modern-cpp-tutorial

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
7.6.bad.example.cpp 525 Bytes
一键复制 编辑 原始数据 按行查看 历史
Changkun Ou 提交于 2019-07-20 00:33 +08:00 . code: update head comments
//
// 7.6.bad.example.cpp
// chapter 7 parallelism and concurrency
// modern c++ tutorial
//
// created by changkun at changkun.de
// https://github.com/changkun/modern-cpp-tutorial
//
#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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gitstr/modern-cpp-tutorial.git
git@gitee.com:gitstr/modern-cpp-tutorial.git
gitstr
modern-cpp-tutorial
modern-cpp-tutorial
master

搜索帮助