1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | /* *
|
|---|
| 2 | * This example is to show the structure of a heap in CIVL.
|
|---|
| 3 | * use the -showSavedStates to see how heap is represented.
|
|---|
| 4 | *
|
|---|
| 5 | */
|
|---|
| 6 | #include<civlc.h>
|
|---|
| 7 |
|
|---|
| 8 | typedef struct Node{
|
|---|
| 9 | int id;
|
|---|
| 10 | struct Node *next;
|
|---|
| 11 | } Node;
|
|---|
| 12 |
|
|---|
| 13 | int *ip;
|
|---|
| 14 | double *dp;
|
|---|
| 15 | Node *q;
|
|---|
| 16 | _Bool start = $false;
|
|---|
| 17 | _Bool finish = $false;
|
|---|
| 18 | int count = 0;
|
|---|
| 19 |
|
|---|
| 20 | void foo(){
|
|---|
| 21 | $when(start);
|
|---|
| 22 | q = (Node *) $malloc($root, sizeof(Node)*2);
|
|---|
| 23 | q[0].id = 1;
|
|---|
| 24 | q[0].next = q+1;
|
|---|
| 25 | q[1].id = 2;
|
|---|
| 26 | q[1].next = NULL;
|
|---|
| 27 | count++;
|
|---|
| 28 | if(count == 2){
|
|---|
| 29 | finish=$true;
|
|---|
| 30 | }
|
|---|
| 31 | $when(finish);
|
|---|
| 32 | $free(ip);
|
|---|
| 33 | $free(dp);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | void goo() {
|
|---|
| 37 | $when(start);
|
|---|
| 38 | ip = (int *) $malloc($root, sizeof(int)*3);
|
|---|
| 39 | (*ip) = 1;
|
|---|
| 40 | dp = (double *) $malloc($root, sizeof(double)*4);
|
|---|
| 41 | dp[0] = 1.0;
|
|---|
| 42 | (*(ip+1)) = 2;
|
|---|
| 43 | dp[1] = 2.0;
|
|---|
| 44 | (*(ip+2)) = 3;
|
|---|
| 45 | dp[2] = 3.0;
|
|---|
| 46 | dp[3] = 4.0;
|
|---|
| 47 | count++;
|
|---|
| 48 | if(count == 2){
|
|---|
| 49 | finish=$true;
|
|---|
| 50 | }
|
|---|
| 51 | $when(finish);
|
|---|
| 52 | $free(q);
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | void main() {
|
|---|
| 56 | $proc fp, gp;
|
|---|
| 57 |
|
|---|
| 58 | fp = $spawn foo();
|
|---|
| 59 | gp = $spawn goo();
|
|---|
| 60 | start = $true;
|
|---|
| 61 | $wait fp;
|
|---|
| 62 | $wait gp;
|
|---|
| 63 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.