fork download
  1. #include <iostream>
  2. #include <thread>
  3. #include <vector>
  4. #include <future>
  5.  
  6. class Test {
  7. public:
  8. std::thread t;
  9. std::unique_ptr<std::promise<int>> pp;
  10. Test(std::thread&& rt, std::unique_ptr<std::promise<int>>&& rpp)
  11. : t(std::move(rt)), pp(std::move(rpp))
  12. { }
  13. };
  14.  
  15. int main()
  16. {
  17. std::vector<Test> tests;
  18.  
  19. {
  20. auto pp = std::make_unique<std::promise<int>>();
  21. std::thread t ([p = pp.get()]{
  22. std::cout << 1;
  23. p->set_value(1);
  24. });
  25. tests.push_back(Test(std::move(t), std::move(pp)));
  26. }
  27.  
  28. for(Test& mytest : tests)
  29. {
  30. mytest.t.join();
  31. }
  32.  
  33. }
  34.  
Success #stdin #stdout 0s 82816KB
stdin
Standard input is empty
stdout
1