-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMutEx_BoundedWaiting.cpp
More file actions
66 lines (62 loc) · 973 Bytes
/
MutEx_BoundedWaiting.cpp
File metadata and controls
66 lines (62 loc) · 973 Bytes
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
#include <iostream>
using namespace std;
static class X
{
public:
bool isSet;
int BufferSize;
bool *waiting;
bool key;
bool lock;
int counterProgram;
public:
void Init()
{
isSet=true;
BufferSize=5;
waiting=new bool [BufferSize];
for(int ii=0;ii<BufferSize;ii++)
{
waiting[ii]=false;
}
key=false;
lock=false;
counterProgram=0;
}
void IncCounter()
{
counterProgram++;
}
void DisplayIsSet()
{
cout<<"X.isSet="<<isSet<<endl;
}
void DisplayMsgLn(string msg)
{
DisplayMsg(msg);
cout<<endl;
}
void DisplayMsg(int counter)
{
cout<<counter;
}
void DisplayMsg(string msg)
{
cout<<msg;
}
};
int main()
{
X.IncCounter();
X.DisplayMsg("This is my ");
X.DisplayMsg(X.counterProgram);
X.DisplayMsgLn("th program.");
X.DisplayIsSet();
if(X.isSet==false)
{
X.Init();
X.DisplayMsgLn("After Initialization.");
X.DisplayIsSet();
}
return 0;
}