fork download
  1. #include <bits/stdc++.h>
  2. #include <thread>
  3. # include <mutex>
  4. #define int long long
  5. using namespace std;
  6.  
  7.  
  8. int ans=0;
  9.  
  10. mutex m;
  11.  
  12. void fun(int n){
  13. for(int i=0;i<n;i++){
  14. m.lock();
  15. ans++;
  16. m.unlock();
  17. }
  18. }
  19.  
  20. int32_t main() {
  21.  
  22.  
  23. thread t(fun,1000000);
  24. thread t2(fun,1000000);
  25.  
  26. cout<<ans<<endl;
  27.  
  28. t.join();
  29. t2.join();
  30.  
  31. cout<<ans<<endl;
  32. }
Success #stdin #stdout 0.05s 5436KB
stdin
Standard input is empty
stdout
0
2000000