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
// Created by Solo
// Modified by Bob_li
// Made for Ketan Lalcheta
#include <iostream>
#include <thread>
#include <mutex>
using namespace std;
//OOP functor
class Functor{
mutex m;
int cnt = 0;
public:
void operator()(string s){
for(int i=0; i<100; ++i){
m.lock();
cout << s << ' ' << ++cnt << ' ';
m.unlock();
}
}
int get(){return cnt;}
};
//Functional equivalent
void inc(string& s, int& cnt, mutex& m){
for(int i=0;i<100;++i){
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run