fork download
  1. #include <iostream>
  2. #include <thread>
  3. using namespace std;
  4.  
  5.  
  6. void foo() {
  7. cout << "Thread id: "<<this_thread::get_id()<<endl;
  8. }
  9.  
  10. int main() {
  11. cout << "Supported hardware concurrency: "<<thread::hardware_concurrency()<<endl;
  12.  
  13. thread t1(foo);
  14. cout << "Native handle: "<<t1.native_handle() <<endl;
  15.  
  16. thread t2,t3;
  17. t3=thread(foo); // move assignement t3 start foo now
  18. //t2=t3; // not possible to copy
  19. t2=move(t3); // t2 takes over what t3 was representing
  20.  
  21. t1.join();
  22. t2.join();
  23. return 0;
  24. }
Success #stdin #stdout 0s 19848KB
stdin
Standard input is empty
stdout
Supported hardware concurrency: 4
Native handle: 3075324736
Thread id: 3066936128
Thread id: 3075324736