fork download
  1. #include <iostream>
  2. #include <thread>
  3.  
  4. void threadA() {
  5. int i = 0;
  6. while (++i < 5) {
  7. std::cout << "A" << std::endl;
  8. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  9. }
  10. }
  11. void threadB() {
  12. int i = 0;
  13. while (++i < 5) {
  14. std::cout << "B" << std::endl;
  15. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  16. }
  17. }
  18.  
  19. int main() {
  20. std::thread(threadA).join();
  21. std::thread(threadB).join();
  22. }
Success #stdin #stdout 0s 11608KB
stdin
Standard input is empty
stdout
A
A
A
A
B
B
B
B