source: tests/concurrency/futures/multi.cfa@ 9c8afc7

Last change on this file since 9c8afc7 was 00aa122, checked in by Peter A. Buhr <pabuhr@…>, 4 weeks ago

harmonize single_future with other future types, remove multi_future, marks its test as deprecated, and turn off its test

  • Property mode set to 100644
File size: 1.7 KB
Line 
1// DEPRECATED future type multi_future. Eventually remove this test.
2
3#include <thread.hfa>
4#include <future.hfa>
5
6enum {NFUTURES = 10};
7
8thread Server {
9 int pending, done, iteration;
10 multi_future(int) * request;
11};
12
13void ?{}( Server & this ) {
14 ((thread&)this){"Server Thread"};
15 this.pending = 0;
16 this.done = 0;
17 this.iteration = 0;
18 this.request = 0p;
19}
20
21void ^?{}( Server & mutex this ) {
22 assert(this.pending == 0);
23 this.request = 0p;
24}
25
26void init( Server & this , multi_future(int) * f ) {
27 this.request = f;
28}
29
30void call( Server & mutex this ) {
31 this.pending++;
32}
33
34void finish( Server & mutex this ) {
35 this.done++;
36}
37
38void main( Server & this ) {
39 MAIN_LOOP:
40 for() {
41 waitfor( ^?{} : this ) {
42 break;
43 }
44 or waitfor( call: this ) {
45 if (this.pending != NFUTURES) { continue MAIN_LOOP; }
46
47 this.pending = 0;
48 fulfil( *this.request, this.iteration );
49 this.iteration++;
50
51 for(NFUTURES) {
52 waitfor( finish: this );
53 }
54
55 reset( *this.request );
56 this.done = 0;
57 }
58 }
59
60}
61
62Server * the_server;
63thread Worker {};
64void ?{}(Worker & this) {
65 ((thread&)this){"Worker Thread"};
66}
67
68multi_future(int) * shared_future;
69
70void thrash(void) {
71 volatile int locals[250];
72 for(i; 250) {
73 locals[i] = 0xdeadbeef;
74 }
75}
76
77void work(int num) {
78 call( *the_server );
79 int res = wait( *shared_future );
80 if( res != num ) abort();
81 finish( *the_server );
82}
83
84void main( Worker & ) {
85 for (i; 10) {
86 thrash();
87 work(i);
88 thrash();
89 }
90}
91
92int main() {
93 printf( "start\n" ); // non-empty .expect file
94 processor procs[2];
95 shared_future = new();
96 {
97 Server server;
98 the_server = &server;
99 init(server, shared_future);
100 {
101 Worker workers[NFUTURES];
102 }
103 }
104 delete( shared_future );
105 printf( "done\n" ); // non-empty .expect file
106}
Note: See TracBrowser for help on using the repository browser.