-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
42 lines (34 loc) · 835 Bytes
/
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
#include <iostream>
#include <thread>
void threadFun(int& x, int& y, int& rec)
{
x = 1;
//__asm("DMB ISH"); // Uncomment to fix it!
rec = y;
}
int main(int argc, const char * argv[])
{
uint64_t iter = 0;
int r1 = 0;
int r2 = 0;
while(1)
{
int a = 0;
int b = 0;
std::thread T1(threadFun, std::ref(a), std::ref(b), std::ref(r1));
std::thread T2(threadFun, std::ref(b), std::ref(a), std::ref(r2));
T1.join();
T2.join();
if ((r1 != 0) || (r2 != 0))
{
printf("Iteration %lld: R1 = %d ; R2 = %d\n", iter, r1, r2);
}
else // both R1 and R2 are zero
{
printf("ERROR!! Iteration %lld: R1 = %d ; R2 = %d\n", iter, r1, r2);
return 1;
}
iter++;
}
return 0;
}