-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
123 lines (105 loc) · 2.36 KB
/
main.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "Replica.hpp"
#include <iostream>
const int REQUEST_COUNT = 10000;
int main()
{
Replica r0(0);
Replica r1(1);
Replica r2(2);
Replica r3(3);
Replica r4(4);
r0.addOtherReplica(&r1);
r0.addOtherReplica(&r2);
r0.addOtherReplica(&r3);
r0.addOtherReplica(&r4);
r1.addOtherReplica(&r0);
r1.addOtherReplica(&r2);
r1.addOtherReplica(&r3);
r1.addOtherReplica(&r4);
r2.addOtherReplica(&r0);
r2.addOtherReplica(&r1);
r2.addOtherReplica(&r3);
r2.addOtherReplica(&r4);
r3.addOtherReplica(&r0);
r3.addOtherReplica(&r1);
r3.addOtherReplica(&r2);
r3.addOtherReplica(&r4);
r4.addOtherReplica(&r0);
r4.addOtherReplica(&r1);
r4.addOtherReplica(&r2);
r4.addOtherReplica(&r3);
r0.start();
r1.start();
r2.start();
r3.start();
r4.start();
srand(time(NULL));
std::thread t0([&r0]()
{
int i = 0;
while (++i <= REQUEST_COUNT)
{
Command c;
c.m_type = (Command::CommandType)(rand() % c.CommandTypeNum);
c.m_operand = rand() % 100;
r0.onReceiveRequest(c);
}
});
std::thread t1([&r1]()
{
int i = 0;
while (++i <= REQUEST_COUNT)
{
Command c;
c.m_type = (Command::CommandType)(rand() % c.CommandTypeNum);
c.m_operand = rand() % 100;
r1.onReceiveRequest(c);
}
});
std::thread t2([&r2]()
{
int i = 0;
while (++i <= REQUEST_COUNT)
{
Command c;
c.m_type = (Command::CommandType)(rand() % c.CommandTypeNum);
c.m_operand = rand() % 100;
r2.onReceiveRequest(c);
}
});
std::thread t3([&r3]()
{
int i = 0;
while (++i <= REQUEST_COUNT)
{
Command c;
c.m_type = (Command::CommandType)(rand() % c.CommandTypeNum);
c.m_operand = rand() % 100;
r3.onReceiveRequest(c);
}
});
std::thread t4([&r4]()
{
int i = 0;
while (++i <= REQUEST_COUNT)
{
Command c;
c.m_type = (Command::CommandType)(rand() % c.CommandTypeNum);
c.m_operand = rand() % 100;
r4.onReceiveRequest(c);
}
});
t0.join();
t1.join();
t2.join();
t3.join();
t4.join();
system("pause");
std::cout << "r0 state: " << r0.getState() << std::endl;
std::cout << "r1 state: " << r1.getState() << std::endl;
std::cout << "r2 state: " << r2.getState() << std::endl;
std::cout << "r3 state: " << r3.getState() << std::endl;
std::cout << "r4 state: " << r4.getState() << std::endl;
system("pause");
return 0;
}