-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathdemo_app_mul_sum.c
72 lines (52 loc) · 1.3 KB
/
demo_app_mul_sum.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "event_loop.h"
event_loop_t el;
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int
sum(int arr[], int n) {
int i, sum = 0;
for (i = 0; i < n; i++) {
sum+=arr[i];
}
return sum;
}
int
mul(int arr[], int n) {
int i, mul = 1;
for (i = 0; i < n; i++) {
mul *= arr[i];
}
return mul;
}
typedef struct arg_obj_ {
int *arr;
int n;
} arg_obj_t;
void
sum_wrapper(void *arg) {
arg_obj_t *arg_obj = (arg_obj_t *)arg;
printf ("sum = %d\n", sum(arg_obj->arr, arg_obj->n));
}
void
mul_wrapper(void *arg) {
arg_obj_t *arg_obj = (arg_obj_t *)arg;
printf ("mul = %d\n", mul(arg_obj->arr, arg_obj->n));
}
int
main(int argc, char **argv) {
event_loop_init(&el);
event_loop_run(&el);
sleep(1);
arg_obj_t *arg_obj1 = (arg_obj_t *)calloc(1, sizeof(arg_obj_t));
arg_obj1->arr = arr;
arg_obj1->n = sizeof(arr)/sizeof(arr[0]);
task_t *task_sum = task_create_new_job(&el, sum_wrapper, (void *)arg_obj1);
arg_obj_t *arg_obj2 = (arg_obj_t *)calloc(1, sizeof(arg_obj_t));
arg_obj2->arr = arr;
arg_obj2->n = sizeof(arr)/sizeof(arr[0]);
task_t *task_mul = task_create_new_job(&el, mul_wrapper, (void *)arg_obj2);
printf ("End of main\n");
scanf("\n");
}