source: CIVL/examples/languageFeatures/heapStructure.cvl@ e5c6156

1.23 2.0 main test-branch
Last change on this file since e5c6156 was a82987f, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

$wait is re-implemented as a system function now; examples are updated accordingly.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@664 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 980 bytes
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
8typedef struct Node{
9 int id;
10 struct Node *next;
11} Node;
12
13int *ip;
14double *dp;
15Node *q;
16_Bool start = $false;
17_Bool finish = $false;
18int count = 0;
19
20void 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
36void 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
55void 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.