1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | #include <civlc.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | $proc procs[4];
|
|---|
| 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) {
|
|---|
| 26 | printf("I'm spawned with id %d.\n", id);
|
|---|
| 27 | $assert(procs[id] == $self);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | void main(){
|
|---|
| 31 | int k = minDouble(min, 5, 8);
|
|---|
| 32 |
|
|---|
| 33 | for(int i = 0; i < 4; i++){
|
|---|
| 34 | procs[i] = proc_create(foo, i);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | for(int i = 0; i < 4; i++){
|
|---|
| 38 | $wait(procs[i]);
|
|---|
| 39 | printf("Process %d terminates.\n", i);
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.