source:
CIVL/examples/languageFeatures/atomicBlockedResume.cvl@
a8ca3d3
| Last change on this file since a8ca3d3 was 36b5ada, checked in by , 12 years ago | |
|---|---|
|
|
| File size: 524 bytes | |
| Rev | Line | |
|---|---|---|
| [36b5ada] | 1 | /* Commandline execution: |
| 2 | * civl verify atomicBlockResume.cvl | |
| 3 | * */ | |
| [2c448829] | 4 | #include <civlc.h> |
| 5 | ||
| 6 | int x = 1; | |
| 7 | int y = 0; | |
| 8 | int z = 0; | |
| 9 | int sum = 0; | |
| 10 | ||
| [36b5ada] | 11 | void foo(int i) { |
| 12 | $atomic { | |
| 13 | y = y + i; | |
| 14 | z++; | |
| 15 | // blocked here until x is set to 0 | |
| 16 | $when(x==0) | |
| 17 | switch(y) { | |
| 18 | case 1: sum += 1*i; break; | |
| 19 | case 2: sum += 2*i; break; | |
| 20 | case 3: sum += 3*i; break; | |
| 21 | }; | |
| 22 | } | |
| [2c448829] | 23 | } |
| 24 | ||
| 25 | void main(){ | |
| [36b5ada] | 26 | $atomic { |
| [2c448829] | 27 | $spawn foo(1); |
| 28 | $spawn foo(2); | |
| [36b5ada] | 29 | // blocked here until z++ has been executed twice |
| [2c448829] | 30 | $when (z==2) x = 0; |
| [36b5ada] | 31 | } |
| [2c448829] | 32 | } |
Note:
See TracBrowser
for help on using the repository browser.
