1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 
5 #include "aos_cpp.h"
6 #include <stdio.h>
7 
8 using namespace AOS;
9 
10 #define STACK_BUF_BYTES 2048
11 
12 static thread *pa;
13 static thread *pb;
14 static thread *pc;
15 
demo_task1(void * arg)16 static void demo_task1(void *arg)
17 {
18     int count = 0;
19 
20     while (1) {
21         printf("demo_task1 count  %d\n", count++);
22 
23         pa->sleep((uint32_t)1000);
24 
25         if (count == 5) {
26             pc->start();
27         }
28 
29         if (count == 15) {
30             pc->terminate();
31             pa->terminate();
32         }
33     };
34 }
35 
demo_task2(void * arg)36 static void demo_task2(void *arg)
37 {
38     int count = 0;
39 
40     while (1) {
41         printf("demo_task2 count  %d\n", count++);
42 
43         if (count == 10) {
44             pc->stop();
45             pb->terminate();
46         }
47 
48         pb->sleep((uint32_t)1000);
49     };
50 }
51 
demo_task3(void * arg)52 static void demo_task3(void *arg)
53 {
54     int count = 0;
55 
56     while (1) {
57         printf("demo_task3 count  %d\n", count++);
58 
59         pc->sleep((uint32_t)1000);
60     };
61 }
62 
test_thread(void)63 void test_thread(void)
64 {
65     char *name = (char *)"task";
66     pa         = new thread;
67     pb         = new thread;
68     pc         = new thread;
69 
70     pa->create((const name_t *)name, (void *)NULL, (uint8_t)20, (tick_t)50,
71                STACK_BUF_BYTES, demo_task1, (uint8_t)1);
72 
73     pb->create((const name_t *)name, (void *)NULL, (uint8_t)20, (tick_t)50,
74                STACK_BUF_BYTES, demo_task2, (uint8_t)1);
75 
76     pc->create((const name_t *)name, (void *)NULL, (uint8_t)20, (tick_t)50,
77                STACK_BUF_BYTES, demo_task3, (uint8_t)0);
78 }
79