ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 3aa1d22 was
97e8d1e,
checked in by Peter A. Buhr <pabuhr@…>, 6 years ago
|
add example to compare waitfor and go channels
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // gortn.cfa -- compare waitfor and go channels |
---|
8 | // |
---|
9 | // Author : Peter A. Buhr |
---|
10 | // Created On : Wed Feb 20 08:02:37 2019 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Wed Feb 20 08:35:55 2019 |
---|
13 | // Update Count : 3 |
---|
14 | // |
---|
15 | |
---|
16 | #include <fstream.hfa> |
---|
17 | #include <thread.hfa> |
---|
18 | |
---|
19 | struct Msg { int i, j; }; |
---|
20 | thread Gortn { int i; float f; Msg m; }; |
---|
21 | void ^?{}( Gortn & mutex ) {} |
---|
22 | void mem1( Gortn & mutex gortn, int i ) { gortn.i = i; } |
---|
23 | void mem2( Gortn & mutex gortn, float f ) { gortn.f = f; } |
---|
24 | void mem3( Gortn & mutex gortn, Msg m ) { gortn.m = m; } |
---|
25 | |
---|
26 | void main( Gortn & gortn ) with( gortn ) { |
---|
27 | for ( ;; ) { |
---|
28 | waitfor( mem1, gortn ) sout | i; |
---|
29 | or waitfor( mem2, gortn ) sout | f; |
---|
30 | or waitfor( mem3, gortn ) sout | m.i | m.j; |
---|
31 | or waitfor( ^?{}, gortn ) break; |
---|
32 | } |
---|
33 | } |
---|
34 | int main() { |
---|
35 | Gortn gortn; // start thread |
---|
36 | mem1( gortn, 0 ); |
---|
37 | mem2( gortn, 2.5 ); |
---|
38 | mem3( gortn, (Msg){ 1, 2} ); |
---|
39 | } // wait for completion |
---|
40 | |
---|
41 | // Local Variables: // |
---|
42 | // tab-width: 4 // |
---|
43 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.