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