ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since f1791a4 was
66812dd,
checked in by Peter A. Buhr <pabuhr@…>, 4 years ago
|
convert tests to always print output (no empty .expect files)
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[a77496cb] | 1 | #include <thread.hfa> |
---|
| 2 | enum {NFUTURES = 10}; |
---|
| 3 | |
---|
| 4 | thread Server { |
---|
| 5 | int cnt; |
---|
| 6 | future_t * requests[NFUTURES]; |
---|
| 7 | }; |
---|
| 8 | |
---|
| 9 | void ?{}( Server & this ) { |
---|
| 10 | this.cnt = 0; |
---|
| 11 | for(i; NFUTURES) { |
---|
| 12 | this.requests[i] = 0p; |
---|
| 13 | } |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | void ^?{}( Server & mutex this ) { |
---|
| 17 | assert(this.cnt == 0); |
---|
| 18 | for(i; NFUTURES) { |
---|
| 19 | this.requests[i] = 0p; |
---|
| 20 | } |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | void process( Server & this, int i ) { |
---|
| 24 | if( this.requests[i] == 0p ) return; |
---|
| 25 | future_t * f = this.requests[i]; |
---|
| 26 | this.requests[i] = 0p; |
---|
| 27 | this.cnt--; |
---|
| 28 | fulfil( *f ); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | void call( Server & mutex this, future_t & f ) { |
---|
| 32 | for(i; NFUTURES) { |
---|
| 33 | if( this.requests[i] == 0p ) { |
---|
| 34 | this.requests[i] = &f; |
---|
| 35 | this.cnt++; |
---|
| 36 | return; |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | abort("Monitor Error"); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | void main( Server & this ) { |
---|
| 43 | unsigned i = 0; |
---|
| 44 | for() { |
---|
| 45 | waitfor( ^?{} : this ) { |
---|
| 46 | break; |
---|
| 47 | } |
---|
| 48 | or when( this.cnt < NFUTURES ) waitfor( call: this ) {} |
---|
| 49 | or else { |
---|
| 50 | process( this, i % NFUTURES ); |
---|
| 51 | i++; |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | for(i; NFUTURES) { |
---|
| 56 | process( this, i ); |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | Server * the_server; |
---|
| 61 | thread Worker {}; |
---|
| 62 | |
---|
| 63 | void thrash(void) { |
---|
| 64 | volatile int locals[250]; |
---|
| 65 | for(i; 250) { |
---|
| 66 | locals[i] = 0xdeadbeef; |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void work(void) { |
---|
| 71 | future_t mine; |
---|
| 72 | call( *the_server, mine ); |
---|
| 73 | wait( mine ); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | void main( Worker & ) { |
---|
| 77 | for(150) { |
---|
| 78 | thrash(); |
---|
| 79 | work(); |
---|
| 80 | thrash(); |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | int main() { |
---|
| 85 | processor procs[2]; |
---|
| 86 | { |
---|
| 87 | Server server; |
---|
| 88 | the_server = &server; |
---|
| 89 | { |
---|
| 90 | Worker workers[17]; |
---|
| 91 | } |
---|
| 92 | } |
---|
[66812dd] | 93 | printf( "done\n" ); // non-empty .expect file |
---|
| 94 | |
---|
| 95 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.