-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLockGuard.cpp
41 lines (35 loc) · 1.01 KB
/
LockGuard.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
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* \file LockGuard.cpp
* \brief
*
* \todo
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
std::mutex m1;
//--------------------------------------------------------------------------------------------------
void
shared_print(std::string msg, int id)
{
std::lock_guard<std::mutex> guard(m1);
std::cout << msg << " :: " << id << std::endl;
}
//--------------------------------------------------------------------------------------------------
void
function1()
{
for (int i = 0; i > -10; i--)
shared_print("From t1", i);
}
//--------------------------------------------------------------------------------------------------
int main()
{
std::thread t1(function1);
for (int i = 0; i < 10 ; i++)
shared_print("From Main", i);
t1.join();
return 0;
}
//--------------------------------------------------------------------------------------------------