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