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 Ketan Lalcheta
#include <iostream>
#include <mutex>
#include <thread>
#include <vector>
using namespace std;
mutex mx;
int i1;
thread_local int i2;
void addOne(){
cout << this_thread::get_id() << '\n';
lock_guard<mutex> lg(mx);
cout << "int i1 = " << ++i1
<< " thread_local int i2 = " << ++i2
<< '\n';
}
int main() {
cout << "initial value:\n"
<< "int i1 = " << i1
<< " thread_local int i2 = " << i2
<< "\n\n";
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run