ADTast-experimentalpthread-emulationqualifiedEnum
Last change
on this file since e1a9c77 was
55422cf,
checked in by caparsons <caparson@…>, 2 years ago
|
added tests for pthread lock and cond var
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | #include <stdio.h> |
---|
2 | #include "locks.hfa" |
---|
3 | #include <stdlib.hfa> |
---|
4 | #include <thread.hfa> |
---|
5 | |
---|
6 | const unsigned int num_times = 50000; |
---|
7 | |
---|
8 | simple_owner_lock l; |
---|
9 | pthread_cond_var( simple_owner_lock ) c; |
---|
10 | |
---|
11 | volatile int counter = 0; |
---|
12 | |
---|
13 | thread Wait_Signal_1 {}; |
---|
14 | |
---|
15 | void main( Wait_Signal_1 & this ) { |
---|
16 | for (unsigned int i = 0; i < num_times; i++) { |
---|
17 | lock(l); |
---|
18 | if(empty(c) && i != num_times - 1) { |
---|
19 | wait(c,l); |
---|
20 | }else{ |
---|
21 | notify_one(c); |
---|
22 | } |
---|
23 | unlock(l); |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | thread Wait_3_Signal_3 {}; |
---|
28 | |
---|
29 | void main( Wait_3_Signal_3 & this ) { |
---|
30 | for (unsigned int i = 0; i < num_times; i++) { |
---|
31 | lock(l); |
---|
32 | counter++; |
---|
33 | if(counter == 4 || i == num_times - 1) { |
---|
34 | counter = 0; |
---|
35 | notify_all(c); |
---|
36 | }else{ |
---|
37 | wait(c,l); |
---|
38 | } |
---|
39 | unlock(l); |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | thread Rec_Lock_Wait_Signal_1 {}; |
---|
44 | |
---|
45 | void main( Rec_Lock_Wait_Signal_1 & this ) { |
---|
46 | for (unsigned int i = 0; i < num_times; i++) { |
---|
47 | lock(l); |
---|
48 | lock(l); |
---|
49 | lock(l); |
---|
50 | if(empty(c) && i != num_times - 1) { |
---|
51 | wait(c,l); |
---|
52 | }else{ |
---|
53 | notify_one(c); |
---|
54 | } |
---|
55 | unlock(l); |
---|
56 | unlock(l); |
---|
57 | unlock(l); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | int main() { |
---|
62 | processor p[3]; |
---|
63 | printf("Start Test 1: lock and condition variable single wait/notify\n"); |
---|
64 | { |
---|
65 | Wait_Signal_1 t1[2]; |
---|
66 | } |
---|
67 | printf("Done Test 1\n"); |
---|
68 | |
---|
69 | printf("Start Test 2: lock and condition variable 3 wait/notify all\n"); |
---|
70 | { |
---|
71 | Wait_3_Signal_3 t1[4]; |
---|
72 | } |
---|
73 | printf("Done Test 2\n"); |
---|
74 | |
---|
75 | printf("Start Test 3: lock and condition variable multiple acquire and wait/notify\n"); |
---|
76 | { |
---|
77 | Rec_Lock_Wait_Signal_1 t1[2]; |
---|
78 | } |
---|
79 | printf("Done Test 3\n"); |
---|
80 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.