source:
CIVL/examples/backend/atomicExample.c
| Last change on this file was ea777aa, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 345 bytes | |
| Rev | Line | |
|---|---|---|
| [c3bddc1] | 1 | #include<stdbool.h> |
| 2 | #include<assert.h> | |
| 3 | #include<civlc.cvh> | |
| [41e6f4e] | 4 | $input int x; |
| [c3bddc1] | 5 | _Bool b=true; |
| 6 | int a=0; | |
| [41e6f4e] | 7 | |
| 8 | void foo(){ | |
| 9 | $atomic{ | |
| [c3bddc1] | 10 | b=false; |
| 11 | $when(x>0); | |
| 12 | b=true; | |
| [41e6f4e] | 13 | } |
| 14 | } | |
| 15 | ||
| 16 | void goo(){ | |
| [c3bddc1] | 17 | if(!b) |
| 18 | a=1; | |
| [41e6f4e] | 19 | } |
| 20 | ||
| [c3bddc1] | 21 | void main(){ |
| 22 | $proc pf, pg; | |
| 23 | ||
| [41e6f4e] | 24 | $atomic{ |
| [c3bddc1] | 25 | pf=$spawn foo(); |
| 26 | pg=$spawn goo(); | |
| [41e6f4e] | 27 | } |
| [c3bddc1] | 28 | $wait(pg); |
| 29 | assert(a==0); | |
| 30 | assert(b); | |
| 31 | $wait(pf); | |
| [41e6f4e] | 32 | } |
Note:
See TracBrowser
for help on using the repository browser.
