fork(4) download
  1. #include <iostream>
  2. #include <thread>
  3. using namespace std;
  4.  
  5. void f() {
  6. cout<<"hello"<<endl;
  7. }
  8.  
  9. int main() {
  10. thread t1(f);
  11. // thread t3 {t1}; // <=== <would cause error: use of deleted function 'std::thread::thread(std::thread&)'
  12. thread t2 {std::move(t1)};
  13. t2.join(); // t2 is the running the thread now - t1 only an empty shell
  14. return 0;
  15. }
Success #stdin #stdout 0s 11656KB
stdin
Standard input is empty
stdout
hello