ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since c0c0bd5 was
76c94bf,
checked in by Thierry Delisle <tdelisle@…>, 4 years ago
|
Added a little bit of debug information to the multi future test.
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[44e37ef] | 1 | #include <thread.hfa> |
---|
| 2 | #include <future.hfa> |
---|
| 3 | |
---|
| 4 | enum {NFUTURES = 10}; |
---|
| 5 | |
---|
| 6 | thread Server { |
---|
| 7 | int cnt, iteration; |
---|
| 8 | multi_future(int) * request; |
---|
| 9 | }; |
---|
| 10 | |
---|
| 11 | void ?{}( Server & this ) { |
---|
[76c94bf] | 12 | ((thread&)this){"Server Thread"}; |
---|
[44e37ef] | 13 | this.cnt = 0; |
---|
| 14 | this.iteration = 0; |
---|
| 15 | this.request = 0p; |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | void ^?{}( Server & mutex this ) { |
---|
| 19 | assert(this.cnt == 0); |
---|
| 20 | this.request = 0p; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | void init( Server & this , multi_future(int) * f ) { |
---|
| 24 | this.request = f; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | void process( Server & mutex this ) { |
---|
| 28 | fulfil( *this.request, this.iteration ); |
---|
| 29 | this.iteration++; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | void call( Server & mutex this ) { |
---|
| 33 | this.cnt++; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | void finish( Server & mutex this ) { } |
---|
| 37 | |
---|
| 38 | void main( Server & this ) { |
---|
| 39 | for() { |
---|
| 40 | waitfor( ^?{} : this ) { |
---|
| 41 | break; |
---|
| 42 | } |
---|
| 43 | or when( this.cnt < NFUTURES ) waitfor( call: this ) { |
---|
| 44 | if (this.cnt == NFUTURES) { |
---|
| 45 | process(this); |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | or waitfor( finish: this ) { |
---|
| 49 | if (this.cnt == NFUTURES) { |
---|
| 50 | reset( *this.request ); |
---|
| 51 | this.cnt = 0; |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | Server * the_server; |
---|
| 59 | thread Worker {}; |
---|
[76c94bf] | 60 | void ?{}(Worker & this) { |
---|
| 61 | ((thread&)this){"Worker Thread"}; |
---|
| 62 | } |
---|
| 63 | |
---|
[44e37ef] | 64 | multi_future(int) * shared_future; |
---|
| 65 | |
---|
| 66 | void thrash(void) { |
---|
| 67 | volatile int locals[250]; |
---|
| 68 | for(i; 250) { |
---|
| 69 | locals[i] = 0xdeadbeef; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void work(int num) { |
---|
| 74 | call( *the_server ); |
---|
| 75 | int res = wait( *shared_future ); |
---|
| 76 | if( res != num ) abort(); |
---|
| 77 | finish( *the_server ); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | void main( Worker & ) { |
---|
| 81 | for (i; 10) { |
---|
| 82 | thrash(); |
---|
| 83 | work(i); |
---|
| 84 | thrash(); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | int main() { |
---|
| 89 | printf( "start\n" ); // non-empty .expect file |
---|
| 90 | processor procs[2]; |
---|
| 91 | shared_future = new(); |
---|
| 92 | { |
---|
| 93 | Server server; |
---|
| 94 | the_server = &server; |
---|
| 95 | init(server, shared_future); |
---|
| 96 | { |
---|
| 97 | Worker workers[NFUTURES]; |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | delete( shared_future ); |
---|
| 101 | printf( "done\n" ); // non-empty .expect file |
---|
| 102 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.