source: CIVL/examples/concurrency/adder.cvl@ 97cfc53

1.23 2.0 main test-branch
Last change on this file since 97cfc53 was 793cfc2, checked in by Tim Zirkel <zirkeltk@…>, 13 years ago

Reorganized examples and tests. Added algebra, assoc, dining, assume, and scoping examples.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@163 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 622 bytes
Line 
1#include <civlc.h>
2$input double a[3];
3
4double adderSeq(int n) {
5 double s = 0.0;
6
7 for (int i = 0; i < n; i++) {
8 s += a[i];
9 }
10 return s;
11}
12
13double adderPar(int m) {
14 double s = 0.0;
15 int mutex = 0;
16 $proc workers[m];
17
18 void worker(int i) {
19 double t;
20
21 $when (mutex == 0) mutex = 1;
22 t = s;
23 t += a[i];
24 s = t;
25 mutex = 0;
26 }
27
28 for (int j = 0; j < m; j++) {
29 workers[j] = $spawn worker(j);
30 }
31 for (int k = 0; k < m; k++) {
32 $wait workers[k];
33 }
34 return s;
35}
36
37void main() {
38 double seq;
39 double par;
40
41 seq = adderSeq(3);
42 par = adderPar(3);
43 $assert seq == par;
44}
Note: See TracBrowser for help on using the repository browser.