source:
CIVL/examples/languageFeatures/atomicBlockedResume.cvl
| Last change on this file was ea777aa, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 625 bytes | |
| Rev | Line | |
|---|---|---|
| [36b5ada] | 1 | /* Commandline execution: |
| 2 | * civl verify atomicBlockResume.cvl | |
| 3 | * */ | |
| [e6b02c8] | 4 | #include <civlc.cvh> |
| [2c448829] | 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 | |
| [a3da6fb] | 16 | $yield(); |
| [36b5ada] | 17 | $when(x==0) |
| [a3da6fb] | 18 | switch(y) { |
| 19 | case 1: sum += 1*i; break; | |
| 20 | case 2: sum += 2*i; break; | |
| 21 | case 3: sum += 3*i; break; | |
| 22 | }; | |
| [36b5ada] | 23 | } |
| [2c448829] | 24 | } |
| 25 | ||
| 26 | void main(){ | |
| [48bfab9] | 27 | $proc fp1, fp2; |
| 28 | ||
| [36b5ada] | 29 | $atomic { |
| [48bfab9] | 30 | fp1 = $spawn foo(1); |
| 31 | fp2 = $spawn foo(2); | |
| [36b5ada] | 32 | // blocked here until z++ has been executed twice |
| [a3da6fb] | 33 | $yield(); |
| [2c448829] | 34 | $when (z==2) x = 0; |
| [36b5ada] | 35 | } |
| [48bfab9] | 36 | $wait(fp1); |
| 37 | $wait(fp2); | |
| [2c448829] | 38 | } |
Note:
See TracBrowser
for help on using the repository browser.
