ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change
on this file since 24ebddac was
af67ee1,
checked in by caparsons <caparson@…>, 3 years ago
|
Added support for locks as parameters to mutex stmt
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | #include <mutex_stmt.hfa> |
---|
2 | #include <locks.hfa> |
---|
3 | |
---|
4 | const unsigned int num_times = 10000; |
---|
5 | |
---|
6 | owner_lock m1, m2, m3, m4, m5; |
---|
7 | |
---|
8 | thread T_Mutex {}; |
---|
9 | bool insideFlag = false; |
---|
10 | int count = 0; |
---|
11 | |
---|
12 | void main( T_Mutex & this ) { |
---|
13 | for (unsigned int i = 0; i < num_times; i++) { |
---|
14 | mutex ( m1 ) count++; |
---|
15 | mutex ( m1 ) { |
---|
16 | assert(!insideFlag); |
---|
17 | insideFlag = true; |
---|
18 | assert(insideFlag); |
---|
19 | insideFlag = false; |
---|
20 | } |
---|
21 | } |
---|
22 | } |
---|
23 | |
---|
24 | thread T_Multi {}; |
---|
25 | |
---|
26 | void main( T_Multi & this ) { |
---|
27 | for (unsigned int i = 0; i < num_times; i++) { |
---|
28 | mutex ( m1 ) { |
---|
29 | assert(!insideFlag); |
---|
30 | insideFlag = true; |
---|
31 | assert(insideFlag); |
---|
32 | insideFlag = false; |
---|
33 | } |
---|
34 | mutex ( m1, m2, m3, m4, m5 ) { |
---|
35 | assert(!insideFlag); |
---|
36 | insideFlag = true; |
---|
37 | assert(insideFlag); |
---|
38 | insideFlag = false; |
---|
39 | } |
---|
40 | mutex ( m3, m1 ) { |
---|
41 | assert(!insideFlag); |
---|
42 | insideFlag = true; |
---|
43 | assert(insideFlag); |
---|
44 | insideFlag = false; |
---|
45 | } |
---|
46 | mutex ( m1, m2, m4 ) { |
---|
47 | assert(!insideFlag); |
---|
48 | insideFlag = true; |
---|
49 | assert(insideFlag); |
---|
50 | insideFlag = false; |
---|
51 | } |
---|
52 | mutex ( m1, m3, m4, m5 ) { |
---|
53 | assert(!insideFlag); |
---|
54 | insideFlag = true; |
---|
55 | assert(insideFlag); |
---|
56 | insideFlag = false; |
---|
57 | } |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | int main() { |
---|
63 | processor p[10]; |
---|
64 | |
---|
65 | printf("Start Test: single lock mutual exclusion\n"); |
---|
66 | { |
---|
67 | T_Mutex t[1]; |
---|
68 | } |
---|
69 | printf("End Test: single lock mutual exclusion\n"); |
---|
70 | printf("Start Test: multi lock deadlock/mutual exclusion\n"); |
---|
71 | { |
---|
72 | T_Multi t[10]; |
---|
73 | } |
---|
74 | printf("End Test: multi lock deadlock/mutual exclusion\n"); |
---|
75 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.