ADTast-experimental
Last change
on this file since b5513f1 was
a33a5e2,
checked in by caparsons <caparson@…>, 18 months ago
|
added tests for the waituntil stmt
|
-
Property mode set to
100644
|
File size:
1.8 KB
|
Rev | Line | |
---|
[a33a5e2] | 1 | #include <select.hfa> |
---|
| 2 | #include <thread.hfa> |
---|
| 3 | #include <locks.hfa> |
---|
| 4 | #include <mutex_stmt.hfa> |
---|
| 5 | |
---|
| 6 | multiple_acquisition_lock A; |
---|
| 7 | simple_owner_lock B; |
---|
| 8 | simple_owner_lock C; |
---|
| 9 | |
---|
| 10 | volatile bool done = false; |
---|
| 11 | |
---|
| 12 | thread Server1 {}; |
---|
| 13 | void main( Server1 & this ) { |
---|
| 14 | while( !done ) { |
---|
| 15 | lock(A); |
---|
| 16 | unlock(A); |
---|
| 17 | lock(B); |
---|
| 18 | unlock(B); |
---|
| 19 | lock(C); |
---|
| 20 | unlock(C); |
---|
| 21 | mutex(A,B,C) {}; |
---|
| 22 | } |
---|
| 23 | mutex(sout) sout | "DONE"; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | size_t numtimes = 10000; |
---|
| 27 | int main() { |
---|
| 28 | processor p[3]; |
---|
| 29 | int a = 0, b = 0, c = 0; |
---|
| 30 | printf("start\n"); |
---|
| 31 | { |
---|
| 32 | Server1 s[3]; |
---|
| 33 | for( j; numtimes ) { |
---|
| 34 | for ( int i = 0; i < 8; i++ ) { |
---|
| 35 | |
---|
| 36 | when( i % 2 == 0 ) waituntil( A ) { a++; } |
---|
| 37 | or when( i % 4 < 2 ) waituntil( B ) { b++; } |
---|
| 38 | and when( i < 4 ) waituntil( C ) { c++; } |
---|
| 39 | |
---|
| 40 | ( |
---|
| 41 | when( i % 2 == 0 ) waituntil( A ) { a++; } |
---|
| 42 | or when( i % 4 < 2 ) waituntil( B ) { b++; } |
---|
| 43 | ) |
---|
| 44 | and when( i < 4 ) waituntil( C ) { c++; } |
---|
| 45 | |
---|
| 46 | when( i % 2 == 0 ) waituntil( A ) { a++; } |
---|
| 47 | and when( i % 4 < 2 ) waituntil( B ) { b++; } |
---|
| 48 | and when( i < 4 ) waituntil( C ) { c++; } |
---|
| 49 | |
---|
| 50 | when( i % 2 == 0 ) waituntil( A ) { a++; } |
---|
| 51 | or when( i % 4 < 2 ) waituntil( B ) { b++; } |
---|
| 52 | or when( i < 4 ) waituntil( C ) { c++; } |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | done = true; |
---|
| 56 | } |
---|
| 57 | printf("start recursive acq test\n"); |
---|
| 58 | { |
---|
| 59 | for( j; 10 ) { |
---|
| 60 | lock( A ); |
---|
| 61 | lock( B ); |
---|
| 62 | } |
---|
| 63 | for ( j; 10 ) { |
---|
| 64 | waituntil( A ) { a++; } or waituntil( B ) { b++; } |
---|
| 65 | waituntil( B ) { b++; } or waituntil( A ) { a++; } |
---|
| 66 | } |
---|
| 67 | for( j; 10 ) { |
---|
| 68 | unlock( A ); |
---|
| 69 | unlock( B ); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | printf("done\n"); |
---|
| 73 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.