fork(2) download
  1. #include <iostream>
  2. #include <thread>
  3. #include <functional>
  4.  
  5. class MyClass {
  6. public:
  7. MyClass() {
  8. std::cout << "construction in: " << std::this_thread::get_id() << std::endl;
  9. }
  10.  
  11. MyClass(MyClass const&) {
  12. std::cout << "copy in: " << std::this_thread::get_id() << std::endl;
  13. }
  14.  
  15. MyClass(MyClass &&) {
  16. std::cout << "move in: " << std::this_thread::get_id() << std::endl;
  17. }
  18. };
  19.  
  20. void f(MyClass V) {}
  21.  
  22. int main() {
  23. {
  24. MyClass V;
  25. std::thread t1(f, V);
  26. t1.join();
  27. }
  28. std::cout << "----------\n";
  29. {
  30. MyClass V;
  31. std::thread t2(f, std::ref(V));
  32. t2.join();
  33. }
  34. std::cout << "----------\n";
  35.  
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 4180KB
stdin
Standard input is empty
stdout
construction in: 47380167989184
copy in: 47380167989184
move in: 47380167989184
move in: 47380187178752
----------
construction in: 47380167989184
copy in: 47380187178752
----------