普通Thread的调用方式,要传递一个方法进去,进行调用,查了下win和linux是如此设计,所以thread也这样。这点与java不同
void pause_thread(int n) {
this_thread::sleep_for(chrono::seconds(n));
cout << "pause of" << n << "seconds ended";
thread t(hello);
cout << "id:"<<t.hardware_concurrency << endl;
cout << "native_handle" << t.native_handle()<<endl;
t.join();
thread a(hello);
a.detach();
thread threads[5];
cout << "Spawning 5 threads...\n";
for (int i = 0; i < 5; i++)
{
threads[i] = thread(pause_thread, i + 1);
}
cout << "Done spawning threads.Now waiting for them to join:\n";
for (auto& thread : threads) {
thread.join();
}
cout << "All threads joined!\n";