fork download
  1. #include <thread>
  2. #include <iostream>
  3.  
  4. struct Yoba {
  5. Yoba() { j = ++i; }
  6. void run(const char* desk) { std::cout << desk << ": " << j << std::endl; }
  7. static int i;
  8. int j;
  9. };
  10.  
  11. int Yoba::i{ 0 };
  12.  
  13. int
  14. main()
  15. {
  16. Yoba y1{}; Yoba y2{}; Yoba y3{};
  17. auto th1 = std::thread(&Yoba::run, &y1, "alo");
  18. auto th2 = std::thread(&Yoba::run, &y3, "yoba");
  19. auto th3 = std::thread(&Yoba::run, &y2, "eto ti?");
  20. th1.join();
  21. th2.join();
  22. th3.join();
  23. }
Success #stdin #stdout 0s 28040KB
stdin
Standard input is empty
stdout
eto ti?: 2
yoba: 3
alo: 1