fork(1) download
  1. #include <iostream>
  2. #include <thread>
  3.  
  4. class Bar
  5. {
  6. public:
  7. void foo(int a)
  8. {
  9. std::cout << a << '\n';
  10. }
  11. };
  12.  
  13. int main()
  14. {
  15. Bar bar;
  16.  
  17. // Create and execute the thread
  18. std::thread thread{ &Bar::foo, &bar, 10 }; // Pass 10 to member function
  19.  
  20. // The member function will be executed in a separate thread
  21.  
  22. // Wait for the thread to finish, this is a blocking operation
  23. thread.join();
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 11656KB
stdin
Standard input is empty
stdout
10