MasterGun

Thread

May 16th, 2021 (edited)
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using namespace std;
  2. void threadrun(string threadname) {
  3.     for (int i = 0; i < 10; i++) {
  4.         cout << threadname << " " << i << endl;
  5.         i++;
  6.     }
  7. }
  8. void threadrun2(string threadname2) {
  9.     for (int i = 1; i < 10; i++) {
  10.         cout << threadname2 << " " << i << endl;
  11.         i++;
  12.     }
  13. }
  14. int main() {
  15.     setlocale(LC_ALL, "rus");
  16.     srand(time(NULL));
  17.     thread threadA(threadrun, "threadA");
  18.     thread threadB(threadrun, "threadB");
  19.     thread threadC(threadrun2, "threadC");
  20.     thread threadD(threadrun2, "threadD");
  21.  
  22.     threadA.join();
  23.     threadB.join();
  24.     threadC.join();
  25.     threadD.join();
  26.  
  27.     return 0;
  28. }
RAW Paste Data