Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <thread>
  3.  
  4. using namespace std;
  5.  
  6. void proc(int* n) {
  7.     static const int INC_COUNT = 10000000;
  8.     for (int i = 0; i < INC_COUNT; i++)
  9.         (*n)++;
  10. }
  11.  
  12. int main() {
  13.     int n = 0;
  14.  
  15.     static const int THREAD_COUNT = 2;
  16.     thread* t[THREAD_COUNT];
  17.  
  18.     for (int i = 0; i < THREAD_COUNT; i++)
  19.         t[i] = new thread(proc, &n);
  20.  
  21.     for (int i = 0; i < THREAD_COUNT; i++) {
  22.         t[i]->join();
  23.         delete t[i];
  24.     }
  25.  
  26.     cout << n << endl;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement