source: longrun_tests/locks.cfa @ ffd5948

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

added full length lock test

  • 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        printf("Start Test 1: multi acquisition lock and condition variable single wait/notify\n");
222        {
223                T_C_M_WS1 t1[2];
224        }
225        printf("Done Test 1\n");
226
227        printf("Start Test 2: multi acquisition lock and condition variable 3 wait/notify all\n");
228        {
229                T_C_M_WB1 t1[4];
230        }
231        printf("Done Test 2\n");
232
233        printf("Start Test 3: single acquisition lock and condition variable single wait/notify\n");
234        {
235                T_C_S_WS1 t1[2];
236        }
237        printf("Done Test 3\n");
238
239        printf("Start Test 4: single acquisition lock and condition variable 3 wait/notify all\n");
240        {
241                T_C_S_WB1 t1[4];
242        }
243        printf("Done Test 4\n");
244
245        printf("Start Test 5: owner lock and condition variable single wait/notify\n");
246        {
247                T_C_O_WS1 t1[2];
248        }
249        printf("Done Test 5\n");
250
251        printf("Start Test 6: owner lock and condition variable 3 wait/notify all\n");
252        {
253                T_C_O_WB1 t1[4];
254        }
255        printf("Done Test 6\n");
256
257        printf("Start Test 7: multi acquisiton lock and condition variable multiple acquire and wait/notify\n");
258        {
259                T_C_M_WS2 t1[2];
260        }
261        printf("Done Test 7\n");
262
263        printf("Start Test 8: owner lock and condition variable multiple acquire and wait/notify\n");
264        {
265                T_C_O_WS2 t1[2];
266        }
267        printf("Done Test 8\n");
268
269        printf("Start Test 9: no lock condition variable wait/notify\n");
270        {
271                T_C_NLW t1;
272                T_C_NLS t2;
273        }
274        printf("Done Test 9\n");
275
276        printf("Start Test 10: locked condition variable wait/notify with front()\n");
277        {
278                T_C_S_WNF t1[2];
279        }
280        printf("Done Test 10\n");
281
282        printf("Start Test 11: unlocked condition variable delay wait\n");
283        {
284                T_C_NLWD t1;
285                T_C_WDS t2;
286        }
287        printf("Done Test 11\n");
288
289        printf("Start Test 12: locked condition variable delay wait with unlocked signal\n");
290        {
291                T_C_LWD t1;
292                T_C_WDS t2;
293        }
294        printf("Done Test 12\n");
295
296        printf("Start Test 13: locked condition variable delay wait with locked signal\n");
297        {
298                T_C_LWD t1;
299                T_C_LWDS t2;
300        }
301        printf("Done Test 13\n");
302}
Note: See TracBrowser for help on using the repository browser.