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