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