source: tests/unified_locking/locks.cfa @ 26a249c

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 26a249c was ebd1899, checked in by caparsons <caparson@…>, 3 years ago

tweaked unified locking tests and added expect files

  • Property mode set to 100644
File size: 5.4 KB
Line 
1#include <stdio.h>
2#include "locks.hfa"
3#include <stdlib.hfa>
4#include <thread.hfa>
5
6const unsigned int num_times = 50000;
7
8multiple_acquisition_lock m;
9condition_variable( multiple_acquisition_lock ) c_m;
10
11single_acquisition_lock s;
12condition_variable( single_acquisition_lock ) c_s;
13
14owner_lock o;
15condition_variable( owner_lock ) c_o;
16
17thread T_C_M_WS1 {};
18
19void main( T_C_M_WS1 & this ) {
20        for (unsigned int i = 0; i < num_times; i++) {
21                lock(m);
22                if(empty(c_m) && i != num_times - 1) {
23                        wait(c_m,m);
24                }else{
25                        notify_one(c_m);
26                }
27                unlock(m);
28        }
29}
30
31thread T_C_M_WB1 {};
32
33void main( T_C_M_WB1 & this ) {
34        for (unsigned int i = 0; i < num_times; i++) {
35                lock(m);
36                if(counter(c_m) == 3 || i == num_times - 1) {
37                        notify_all(c_m);
38                }else{
39                        wait(c_m,m);
40                }
41                unlock(m);
42        }
43}
44
45thread T_C_S_WS1 {};
46
47void main( T_C_S_WS1 & this ) {
48        for (unsigned int i = 0; i < num_times; i++) {
49                lock(s);
50                if(empty(c_s) && i != num_times - 1) {
51                        wait(c_s,s);
52                }else{
53                        notify_one(c_s);
54                }
55                unlock(s);
56        }
57}
58
59thread T_C_S_WB1 {};
60
61void main( T_C_S_WB1 & this ) {
62        for (unsigned int i = 0; i < num_times; i++) {
63                lock(s);
64                if(counter(c_s) == 3 || i == num_times - 1) {
65                        notify_all(c_s);
66                }else{
67                        wait(c_s,s);
68                }
69                unlock(s);
70        }
71}
72
73thread T_C_O_WS1 {};
74
75void main( T_C_O_WS1 & this ) {
76        for (unsigned int i = 0; i < num_times; i++) {
77                lock(o);
78                if(empty(c_o) && i != num_times - 1) {
79                        wait(c_o,o);
80                }else{
81                        notify_one(c_o);
82                }
83                unlock(o);
84        }
85}
86
87thread T_C_O_WB1 {};
88
89void main( T_C_O_WB1 & this ) {
90        for (unsigned int i = 0; i < num_times; i++) {
91                lock(o);
92                if(counter(c_o) == 3 || i == num_times - 1) {
93                        notify_all(c_o);
94                }else{
95                        wait(c_o,o);
96                }
97                unlock(o);
98        }
99}
100
101thread T_C_M_WS2 {};
102
103void main( T_C_M_WS2 & this ) {
104        for (unsigned int i = 0; i < num_times; i++) {
105                lock(m);
106                lock(m);
107                lock(m);
108                if(empty(c_m) && i != num_times - 1) {
109                        wait(c_m,m);
110                }else{
111                        notify_one(c_m);
112                }
113                unlock(m);
114                unlock(m);
115                unlock(m);
116        }
117}
118
119thread T_C_O_WS2 {};
120
121void main( T_C_O_WS2 & this ) {
122        for (unsigned int i = 0; i < num_times; i++) {
123                lock(o);
124                lock(o);
125                lock(o);
126                if(empty(c_o) && i != num_times - 1) {
127                        wait(c_o,o);
128                }else{
129                        notify_one(c_o);
130                }
131                unlock(o);
132                unlock(o);
133                unlock(o);
134        }
135}
136
137thread T_C_NLW {};
138
139void main( T_C_NLW & this ) {
140        for (unsigned int i = 0; i < num_times; i++) {
141                wait(c_o);
142        }
143}
144
145thread T_C_NLS {};
146
147void main( T_C_NLS & this ) {
148        for (unsigned int i = 0; i < num_times; i++) {
149                while (empty(c_o)) { }
150                notify_one(c_o);
151        }
152}
153
154thread T_C_S_WNF {};
155
156void main( T_C_S_WNF & this ) {
157        for (unsigned int i = 0; i < num_times; i++) {
158                lock(s);
159                if(empty(c_s) && i != num_times - 1) {
160                        wait(c_s, s, 10);
161                }else{
162                        if(!empty(c_s)) assert(front(c_s) == 10);
163                        notify_one(c_s);
164                }
165                unlock(s);
166        }
167}
168
169bool done = false;
170
171thread T_C_NLWD {};
172
173void main( T_C_NLWD & this ) {
174        done = false;
175        for (unsigned int i = 0; i < num_times/5; i++) {
176                if (i % 1000 == 0) printf("Iteration: %d\n", i);
177                wait(c_s, 1`ns);
178        }
179        done = true;
180}
181
182thread T_C_WDS {};
183
184void main( T_C_WDS & this ) {
185        for (unsigned int i = 0; i < num_times; i++) {
186                while (empty(c_s) && !done) { }
187                notify_one(c_s);
188                sleep(1`ns);
189                if(done) break;
190        }
191}
192
193thread T_C_LWD {};
194
195void main( T_C_LWD & this ) {
196        done = false;
197        for (unsigned int i = 0; i < num_times/5; i++) {
198                if (i % 1000 == 0) printf("Iteration: %d\n", i);
199                lock(s);
200                wait(c_s, s, 1`ns);
201                unlock(s);
202        }
203        done = true;
204}
205
206thread T_C_LWDS {};
207
208void main( T_C_LWDS & this ) {
209        for (unsigned int i = 0; i < num_times; i++) {
210                while (empty(c_s) && !done) { }
211                lock(s);
212                notify_one(c_s);
213                unlock(s);
214                sleep(1`ns);
215                if(done) break;
216        }
217}
218
219int main() {
220        processor p[2];
221        wait( c_s, 1`ns );
222        printf("Start Test 1: multi acquisition lock and condition variable single wait/notify\n");
223        {
224                T_C_M_WS1 t1[2];
225        }
226        printf("Done Test 1\n");
227
228        printf("Start Test 2: multi acquisition lock and condition variable 3 wait/notify all\n");
229        {
230                T_C_M_WB1 t1[4];
231        }
232        printf("Done Test 2\n");
233
234        printf("Start Test 3: single acquisition lock and condition variable single wait/notify\n");
235        {
236                T_C_S_WS1 t1[2];
237        }
238        printf("Done Test 3\n");
239
240        printf("Start Test 4: single acquisition lock and condition variable 3 wait/notify all\n");
241        {
242                T_C_S_WB1 t1[4];
243        }
244        printf("Done Test 4\n");
245
246        printf("Start Test 5: owner lock and condition variable single wait/notify\n");
247        {
248                T_C_O_WS1 t1[2];
249        }
250        printf("Done Test 5\n");
251
252        printf("Start Test 6: owner lock and condition variable 3 wait/notify all\n");
253        {
254                T_C_O_WB1 t1[4];
255        }
256        printf("Done Test 6\n");
257
258        printf("Start Test 7: multi acquisiton lock and condition variable multiple acquire and wait/notify\n");
259        {
260                T_C_M_WS2 t1[2];
261        }
262        printf("Done Test 7\n");
263
264        printf("Start Test 8: owner lock and condition variable multiple acquire and wait/notify\n");
265        {
266                T_C_O_WS2 t1[2];
267        }
268        printf("Done Test 8\n");
269
270        printf("Start Test 9: no lock condition variable wait/notify\n");
271        {
272                T_C_NLW t1;
273                T_C_NLS t2;
274        }
275        printf("Done Test 9\n");
276
277        printf("Start Test 10: locked condition variable wait/notify with front()\n");
278        {
279                T_C_S_WNF t1[2];
280        }
281        printf("Done Test 10\n");
282
283        printf("Start Test 11: unlocked condition variable delay wait\n");
284        {
285                T_C_NLWD t1;
286                T_C_WDS t2;
287        }
288        printf("Done Test 11\n");
289
290        printf("Start Test 12: locked condition variable delay wait with unlocked signal\n");
291        {
292                T_C_LWD t1;
293                T_C_WDS t2;
294        }
295        printf("Done Test 12\n");
296
297        printf("Start Test 13: locked condition variable delay wait with locked signal\n");
298        {
299                T_C_LWD t1;
300                T_C_LWDS t2;
301        }
302        printf("Done Test 13\n");
303}
Note: See TracBrowser for help on using the repository browser.