26.多线程join detach
生活随笔
收集整理的這篇文章主要介紹了
26.多线程join detach
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 #include <iostream>
2 #include <thread>
3 #include <array>
4 #include <Windows.h>
5 using namespace std;
6
7 void show()
8 {
9 MessageBoxA(0, "1", "1", 0);
10 }
11
12 void main()
13 {
14 //獲取CPU核心的個數
15 auto n = thread::hardware_concurrency();
16 cout << "CPU核心個數:" << n << endl;
17 array<thread, 3> threads{thread(show), thread(show), thread(show)};
18
19 for (int i=0;i<3;i++)
20 {
21 //使用join后主線程等待執行完之后才結束
22 //threads[i].join();
23 //脫離主線程,主線程結束不報錯,自動退出
24 threads[i].detach();
25 }
26
27 Sleep(3000);
28 }
?
轉載于:https://www.cnblogs.com/xiaochi/p/8546095.html
總結
以上是生活随笔為你收集整理的26.多线程join detach的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 20165305 苏振龙 《Java 程
- 下一篇: const常量与define宏定义的区别