fork(8) download
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <thread>
  4.  
  5. using namespace std;
  6.  
  7. void count_asc();
  8. void count_desc();
  9.  
  10. int main() {
  11. thread first(count_asc);
  12. thread second(count_desc);
  13.  
  14. first.join();
  15. second.join();
  16.  
  17. system("pause");
  18. return 0;
  19. }
  20.  
  21. void count_asc(){
  22. int ctr;
  23. for(ctr=1;ctr<=10;ctr++){
  24. cout<<"First thread: "<<ctr<<endl;
  25. }
  26. }
  27.  
  28. void count_desc(){
  29. int ctr;
  30. for(ctr=10;ctr>=1;ctr--){
  31. cout<<"Second thread: "<<ctr<<endl;
  32. }
  33. }
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