CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Made for Ketan Lalcheta
// Run the code a dozen times to see its various execution.
#include <iostream>
#include <thread>
#include <mutex>
using namespace std;
class Functor
{
public:
void operator()(string n){
//Simulation of complex calculations
int i = 0;
for(; i<100; ++i){
m.lock();
cout
<< n
//<< i
<< ++cnt
<<' ';
m.unlock();
}
}
int get(){return cnt;}
private:
mutex m;
//int i = 0;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run