-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicXML.cpp
More file actions
74 lines (61 loc) · 1.73 KB
/
BasicXML.cpp
File metadata and controls
74 lines (61 loc) · 1.73 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* \file BasicXML.cpp
* \brief
*
* \todo
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
class Application
{
std::mutex m_mutex;
bool m_bDataLoaded;
public:
Application()
{
m_bDataLoaded = false;
}
void loadData()
{
// Make This Thread sleep for 1 Second
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::cout<<"Loading Data from XML"<<std::endl;
// Lock The Data structure
std::lock_guard<std::mutex> guard(m_mutex);
// Set the flag to true, means data is loaded
m_bDataLoaded = true;
}
void mainTask()
{
std::cout<<"Do Some Handshaking"<<std::endl;
// Acquire the Lock
m_mutex.lock();
// Check if flag is set to true or not
while(m_bDataLoaded != true)
{
// Release the lock
m_mutex.unlock();
//sleep for 100 milli seconds
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Acquire the lock
m_mutex.lock();
}
// Release the lock
m_mutex.unlock();
//Doc processing on loaded Data
std::cout<<"Do Processing On loaded Data"<<std::endl;
}
};
//--------------------------------------------------------------------------------------------------
int main()
{
Application app;
std::thread thread_1(&Application::mainTask, &app);
std::thread thread_2(&Application::loadData, &app);
thread_2.join();
thread_1.join();
return 0;
}
//--------------------------------------------------------------------------------------------------