This commit is contained in:
Light-City
2020-02-01 09:20:20 +08:00
parent 93f55802fa
commit 5318869025
16 changed files with 900 additions and 12 deletions

View File

@@ -0,0 +1,35 @@
//
// Created by light on 20-1-31.
//
// join 注意点
/**
* 一旦线程开始我们要想等待线程完成需要在该对象上调用join()
* 双重join将导致程序终止
* 在join之前我们应该检查显示是否可以被join,通过使用joinable()
*/
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
void run(int count) {
while (count-- > 0) {
cout << count << endl;
}
std::this_thread::sleep_for(chrono::seconds(3));
}
int main() {
thread t1(run, 10);
cout << "main()" << endl;
t1.join();
if (t1.joinable()) {
t1.join();
}
cout << "main() after" << endl;
return 0;
}