30 lines
364 B
C++
30 lines
364 B
C++
|
#include <thread>
|
||
|
#include <string>
|
||
|
#include <iostream>
|
||
|
|
||
|
/*
|
||
|
* Compile with 'g++ -pthread a.cpp'
|
||
|
*
|
||
|
* The order of printing is not well-defined
|
||
|
*/
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
void f1() {
|
||
|
cout << "Hello ";
|
||
|
}
|
||
|
|
||
|
void f2(const std::string& s) {
|
||
|
cout << s << endl;
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
thread t1(f1);
|
||
|
thread t2{f2, "Parallel World!"};
|
||
|
|
||
|
t1.join();
|
||
|
t2.join();
|
||
|
|
||
|
return 0;
|
||
|
}
|