1 | #include <mutex_stmt.hfa> |
---|
2 | #include <locks.hfa> |
---|
3 | #include <stats.hfa> |
---|
4 | |
---|
5 | const unsigned int num_times = 10000; |
---|
6 | |
---|
7 | single_acquisition_lock m1, m2, m3, m4, m5; |
---|
8 | |
---|
9 | bool insideFlag = false; |
---|
10 | int count = 0; |
---|
11 | |
---|
12 | thread T_Mutex_Scoped {}; |
---|
13 | |
---|
14 | void main( T_Mutex_Scoped & this ) { |
---|
15 | for (unsigned int i = 0; i < num_times; i++) { |
---|
16 | { |
---|
17 | scoped_lock(single_acquisition_lock) s{m1}; |
---|
18 | count++; |
---|
19 | } |
---|
20 | { |
---|
21 | scoped_lock(single_acquisition_lock) s{m1}; |
---|
22 | assert(!insideFlag); |
---|
23 | insideFlag = true; |
---|
24 | assert(insideFlag); |
---|
25 | insideFlag = false; |
---|
26 | } |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | thread T_Multi_Scoped {}; |
---|
31 | |
---|
32 | void main( T_Multi_Scoped & this ) { |
---|
33 | for (unsigned int i = 0; i < num_times; i++) { |
---|
34 | { |
---|
35 | scoped_lock(single_acquisition_lock) s{m1}; |
---|
36 | assert(!insideFlag); |
---|
37 | insideFlag = true; |
---|
38 | assert(insideFlag); |
---|
39 | insideFlag = false; |
---|
40 | } |
---|
41 | { |
---|
42 | scoped_lock(single_acquisition_lock) s1{m1}; |
---|
43 | scoped_lock(single_acquisition_lock) s2{m2}; |
---|
44 | scoped_lock(single_acquisition_lock) s3{m3}; |
---|
45 | scoped_lock(single_acquisition_lock) s4{m4}; |
---|
46 | scoped_lock(single_acquisition_lock) s5{m5}; |
---|
47 | assert(!insideFlag); |
---|
48 | insideFlag = true; |
---|
49 | assert(insideFlag); |
---|
50 | insideFlag = false; |
---|
51 | } |
---|
52 | { |
---|
53 | scoped_lock(single_acquisition_lock) s1{m1}; |
---|
54 | scoped_lock(single_acquisition_lock) s3{m3}; |
---|
55 | assert(!insideFlag); |
---|
56 | insideFlag = true; |
---|
57 | assert(insideFlag); |
---|
58 | insideFlag = false; |
---|
59 | } |
---|
60 | { |
---|
61 | scoped_lock(single_acquisition_lock) s1{m1}; |
---|
62 | scoped_lock(single_acquisition_lock) s2{m2}; |
---|
63 | scoped_lock(single_acquisition_lock) s4{m4}; |
---|
64 | assert(!insideFlag); |
---|
65 | insideFlag = true; |
---|
66 | assert(insideFlag); |
---|
67 | insideFlag = false; |
---|
68 | } |
---|
69 | { |
---|
70 | scoped_lock(single_acquisition_lock) s1{m1}; |
---|
71 | scoped_lock(single_acquisition_lock) s3{m3}; |
---|
72 | scoped_lock(single_acquisition_lock) s4{m4}; |
---|
73 | scoped_lock(single_acquisition_lock) s5{m5}; |
---|
74 | assert(!insideFlag); |
---|
75 | insideFlag = true; |
---|
76 | assert(insideFlag); |
---|
77 | insideFlag = false; |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | int num_tasks = 10; |
---|
83 | int main() { |
---|
84 | processor p[10]; |
---|
85 | |
---|
86 | printf("Start Test: single scoped lock mutual exclusion\n"); |
---|
87 | { |
---|
88 | T_Mutex_Scoped t[10]; |
---|
89 | } |
---|
90 | assert(count == num_tasks * num_times); |
---|
91 | printf("End Test: single scoped lock mutual exclusion\n"); |
---|
92 | printf("Start Test: multi scoped lock deadlock/mutual exclusion\n"); |
---|
93 | { |
---|
94 | T_Multi_Scoped t[10]; |
---|
95 | } |
---|
96 | printf("End Test: multi scoped lock deadlock/mutual exclusion\n"); |
---|
97 | } |
---|