-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
45 lines (32 loc) · 950 Bytes
/
test.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
#include <mthpc/thread.h>
#include <mthpc/print.h>
static void thread_a(struct mthpc_thread_group *th)
{
static int local_cnt = 0;
if (++local_cnt == 2)
*(int *)th->args = 1;
mthpc_pr_info("thread A called:%d\n", local_cnt);
return;
}
static void thread_b(struct mthpc_thread_group *th)
{
static int local_cnt = 0;
local_cnt++;
mthpc_pr_info("thread B called:%d\n", local_cnt);
return;
}
static int th_arg_a = 0;
static MTHPC_DECLARE_THREAD_GROUP(th_obj_a, 1, thread_a, NULL, &th_arg_a);
static MTHPC_DECLARE_THREAD_GROUP(th_obj_b, 1, thread_b, NULL, NULL);
static MTHPC_DECLARE_THREAD_CLUSTER(thg_obj, &th_obj_a, &th_obj_b);
int main(void)
{
/* Run thread group object */
mthpc_thread_run(&thg_obj);
/* Run thread object */
mthpc_thread_run(&th_obj_a);
mthpc_thread_run(&th_obj_b);
mthpc_thread_run(&thg_obj);
mthpc_pr_info("th_arg_a=%d\n", th_arg_a);
return 0;
}