29 lines
364 B
C++
Executable file
29 lines
364 B
C++
Executable file
#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;
|
|
}
|