fork download
  1. #include <cstdlib>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <thread>
  5. #include <future>
  6.  
  7. int main()
  8. {
  9. std::vector<int> v(1ul<<27);
  10.  
  11. auto f(begin(v)), m(f+v.size()/2), l(end(v));
  12. std::generate(f, l, rand);
  13.  
  14. #if 0
  15. auto t1 = std::thread([&] () mutable { std::sort(f,m); } );
  16. auto t2 = std::thread([&] () mutable { std::sort(m,l); } );
  17. t1.join();
  18. t2.join();
  19. #else
  20. auto f1 = std::async(std::launch::async, [&] () mutable { std::sort(f,m); } );
  21. auto f2 = std::async(std::launch::async, [&] () mutable { std::sort(m,l); } );
  22. f1.get();
  23. f2.get();
  24. #endif
  25.  
  26. std::inplace_merge(f,m,l);
  27. }
  28.  
Runtime error #stdin #stdout 3.68s 527360KB
stdin
Standard input is empty
stdout
Standard output is empty