1.23
2.0
main
test-branch
| Rev | Line | |
|---|
| [f1be440] | 1 | #include <civlc.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| [c358a25] | 3 | $proc procs[4];
|
|---|
| [f1be440] | 4 |
|
|---|
| 5 | int min(int a, int b) {
|
|---|
| 6 | if (a < b)
|
|---|
| 7 | return a;
|
|---|
| 8 | else
|
|---|
| 9 | return b;
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | int minDouble(int (*f)(int, int), int a, int b) {
|
|---|
| 13 | int result;
|
|---|
| 14 |
|
|---|
| 15 | result = f(a, b);
|
|---|
| 16 | return result * 2;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | $proc proc_create(void (*f)(int), int x){
|
|---|
| 20 | $proc p = $spawn f(x);
|
|---|
| 21 |
|
|---|
| 22 | return p;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | void foo(int id) {
|
|---|
| [d46c68d] | 26 | _Bool checkPid = equalsTo(procs[id], $self);
|
|---|
| 27 |
|
|---|
| [f1be440] | 28 | printf("I'm spawned with id %d.\n", id);
|
|---|
| [d46c68d] | 29 | $assert(checkPid);
|
|---|
| [f1be440] | 30 | }
|
|---|
| 31 |
|
|---|
| 32 | void main(){
|
|---|
| 33 | int k = minDouble(min, 5, 8);
|
|---|
| [c358a25] | 34 |
|
|---|
| [f1be440] | 35 | for(int i = 0; i < 4; i++){
|
|---|
| 36 | procs[i] = proc_create(foo, i);
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | for(int i = 0; i < 4; i++){
|
|---|
| 40 | $wait(procs[i]);
|
|---|
| 41 | printf("Process %d terminates.\n", i);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.