当前位置 : 主页 > 编程语言 > c++ >

[c++11多线程]01

来源:互联网 收集:自由互联 发布时间:2021-06-23
1 #include QCoreApplication 2 3 4 // 1.Approaches to concurrency 5 // Each developer represents a thread,and each office represents a process 6 // --1The first approach is to have multiole single-threaded processes -- concurrency with multi

 

 1 #include <QCoreApplication>
 2 
 3 
 4 //1.Approaches to concurrency
 5 //  Each developer represents a thread,and each office represents a process
 6 //--<1>The first approach is to have multiole single-threaded processes --> concurrency with multiple processes
 7 //      ,which is similar to having each developer in threir own office.
 8 //--<2># focus on #The second approach is to have multiple threads in a single process,-->concurrency with multiple threads
 9 //      ,which is like having two developers in the same office.
10 
11 
12 //2.Why use concurrency?
13 //<1>separation of concerns
14 //<2>performance
15 
16 #include <iostream>
17 #include <thread>
18 
19 using namespace std;
20 
21 void hello()
22 {
23     cout<<"say hello"<<endl;
24 }
25 int main(int argc, char *argv[])
26 {
27     QCoreApplication a(argc, argv);
28 
29     thread t(hello);
30     t.join();
31 
32 
33     return a.exec();
34 }
网友评论