fork download
  1. #include <iostream>
  2. #include <thread>
  3. using namespace std;
  4.  
  5. class Thread {
  6. public:
  7.  
  8. typedef void (thread::*Action)();
  9.  
  10. Thread(thread && t, Action a) : th(move(t)), pAction(a) {}
  11.  
  12. ~Thread()
  13. {
  14. if (th.joinable()) (th.*pAction)();
  15. }
  16.  
  17. private:
  18.  
  19. Action pAction;
  20. thread th;
  21. };
  22.  
  23. void work()
  24. {
  25. }
  26.  
  27. int main()
  28. {
  29. Thread t1(thread(work), &thread::join);
  30. Thread t2(thread(work), &thread::detach);
  31. }
  32.  
Runtime error #stdin #stdout #stderr 0s 3428KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted