ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change
on this file since 8631c84 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.5 KB
|
Rev | Line | |
---|
[a4d098c] | 1 | #include <monitor.hfa> |
---|
[af67ee1] | 2 | #include <mutex_stmt.hfa> |
---|
[a4d098c] | 3 | #include <stdio.h> |
---|
| 4 | #include <stdlib.hfa> |
---|
| 5 | #include <thread.hfa> |
---|
| 6 | |
---|
| 7 | const unsigned int num_times = 10000; |
---|
| 8 | |
---|
| 9 | monitor monitor_t {}; |
---|
| 10 | |
---|
| 11 | monitor_t m1, m2, m3, m4, m5; |
---|
| 12 | |
---|
| 13 | thread T_Mutex {}; |
---|
| 14 | bool insideFlag = false; |
---|
| 15 | int count = 0; |
---|
[af67ee1] | 16 | bool startFlag = false; |
---|
[a4d098c] | 17 | |
---|
| 18 | void main( T_Mutex & this ) { |
---|
| 19 | for (unsigned int i = 0; i < num_times; i++) { |
---|
| 20 | mutex ( m1 ) count++; |
---|
| 21 | mutex ( m1 ) { |
---|
| 22 | assert(!insideFlag); |
---|
| 23 | insideFlag = true; |
---|
| 24 | assert(insideFlag); |
---|
| 25 | insideFlag = false; |
---|
| 26 | } |
---|
| 27 | } |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | thread T_Multi {}; |
---|
| 31 | |
---|
| 32 | void main( T_Multi & this ) { |
---|
| 33 | for (unsigned int i = 0; i < num_times; i++) { |
---|
| 34 | mutex ( m1 ) { |
---|
| 35 | assert(!insideFlag); |
---|
| 36 | insideFlag = true; |
---|
| 37 | assert(insideFlag); |
---|
| 38 | insideFlag = false; |
---|
| 39 | } |
---|
| 40 | mutex ( m1, m2, m3, m4, m5 ) { |
---|
| 41 | assert(!insideFlag); |
---|
| 42 | insideFlag = true; |
---|
| 43 | assert(insideFlag); |
---|
| 44 | insideFlag = false; |
---|
| 45 | } |
---|
| 46 | mutex ( m3, m1 ) { |
---|
| 47 | assert(!insideFlag); |
---|
| 48 | insideFlag = true; |
---|
| 49 | assert(insideFlag); |
---|
| 50 | insideFlag = false; |
---|
| 51 | } |
---|
| 52 | mutex ( m1, m2, m4 ) { |
---|
| 53 | assert(!insideFlag); |
---|
| 54 | insideFlag = true; |
---|
| 55 | assert(insideFlag); |
---|
| 56 | insideFlag = false; |
---|
| 57 | } |
---|
| 58 | mutex ( m1, m3, m4, m5 ) { |
---|
| 59 | assert(!insideFlag); |
---|
| 60 | insideFlag = true; |
---|
| 61 | assert(insideFlag); |
---|
| 62 | insideFlag = false; |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | int main() { |
---|
| 69 | processor p[10]; |
---|
| 70 | |
---|
| 71 | printf("Start Test: single monitor mutual exclusion\n"); |
---|
| 72 | { |
---|
| 73 | T_Mutex t[10]; |
---|
| 74 | } |
---|
| 75 | printf("End Test: single monitor mutual exclusion\n"); |
---|
| 76 | printf("Start Test: multi monitor deadlock/mutual exclusion\n"); |
---|
| 77 | { |
---|
| 78 | T_Multi t[10]; |
---|
| 79 | } |
---|
| 80 | printf("End Test: multi monitor deadlock/mutual exclusion\n"); |
---|
| 81 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.