source:
CIVL/examples/languageFeatures/atomicFunctionSpecifier.cvl@
a389857
| Last change on this file since a389857 was ea777aa, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 439 bytes | |
| Rev | Line | |
|---|---|---|
| [a8a3f22] | 1 | #include<civlc.cvh> |
| [bf6aebb] | 2 | #include<stdio.h> |
| [a8a3f22] | 3 | |
| [bf6aebb] | 4 | int result[2]; |
| 5 | ||
| 6 | $atomic_f int oneOrTwo(){ | |
| 7 | int res; | |
| 8 | ||
| 9 | $choose{ | |
| 10 | res=1; | |
| 11 | res=2; | |
| 12 | } | |
| 13 | return res; | |
| 14 | } | |
| 15 | ||
| 16 | $atomic_f void increase(int i, int* p){ | |
| [a8a3f22] | 17 | int old=*p; |
| [bf6aebb] | 18 | int step=oneOrTwo(); |
| [a8a3f22] | 19 | |
| [bf6aebb] | 20 | *p=(*p)+step; |
| 21 | $assert(old+step==*p); | |
| 22 | result[i]=*p; | |
| [a8a3f22] | 23 | } |
| 24 | ||
| 25 | int data=0; | |
| 26 | ||
| 27 | void main(){ | |
| 28 | $parfor(int i: 0 .. 1) | |
| [bf6aebb] | 29 | increase(i, &data); |
| 30 | $for(int i: 0 .. 1) | |
| 31 | printf("process %d: result=%d\n", i, result[i]); | |
| [a8a3f22] | 32 | } |
Note:
See TracBrowser
for help on using the repository browser.
