source:
CIVL/examples/concurrency/spawn2.cvl@
23207c6
| Last change on this file since 23207c6 was 2fa36af, checked in by , 13 years ago | |
|---|---|
|
|
| File size: 511 bytes | |
| Rev | Line | |
|---|---|---|
| [20d2740] | 1 | /* spawn2.cvl: simple example of spawning two processes. |
| 2 | * More difficult to reduce than spawn.cvl, because | |
| 3 | * both are accessing variables in the same scope. | |
| 4 | * civl verify -inputN=10 spawn2.cvl | |
| 5 | */ | |
| 6 | #include<civlc.h> | |
| 7 | ||
| 8 | $input int N; | |
| 9 | int s1, s2; | |
| 10 | ||
| 11 | void f1(int n) { | |
| [2fa36af] | 12 | $atomic{ |
| [20d2740] | 13 | s1 = 0; |
| [2fa36af] | 14 | for (int i=0; i<n; i++) s1 += i;} |
| [20d2740] | 15 | } |
| 16 | ||
| 17 | void f2(int n) { | |
| [2fa36af] | 18 | $atomic{ |
| [20d2740] | 19 | s2 = 0; |
| [2fa36af] | 20 | for (int i=0; i<n; i++) s2 += i;} |
| [20d2740] | 21 | } |
| 22 | ||
| 23 | void main() { | |
| 24 | $proc p = $spawn f1(N); | |
| 25 | $proc q = $spawn f2(N); | |
| 26 | ||
| 27 | $wait p; | |
| 28 | $wait q; | |
| 29 | $assert s1==s2; | |
| 30 | } |
Note:
See TracBrowser
for help on using the repository browser.
