6 #include <native/task.h>
7 #include <native/timer.h>
8 #include <native/sem.h>
22 void taskOne(void *arg
)
25 for (i
=0; i
< ITER
; i
++)
27 //rt_printf("Before semGlobal2..............\n");
28 rt_sem_p(&semGlobal2
, 0);
29 rt_printf("I am taskOne and global = %d................\n", ++global
);
30 rt_sem_v(&semGlobal1
);
31 //rt_printf("After semGlobal1..............\n");
35 void taskTwo(void *arg
)
38 for (i
=0; i
< ITER
; i
++)
40 //rt_printf("Before semGlobal1--------------\n");
41 rt_sem_p(&semGlobal1
, 0);
42 rt_printf("I am taskTwo and global = %d----------------\n", --global
);
43 rt_sem_v(&semGlobal2
);
44 //rt_printf("After semGlobal2--------------\n");
48 int main(int argc
, char* argv
[])
50 /* Perform auto-init of rt_print buffers if the task doesn't do so */
51 rt_print_auto_init(1);
53 /* Avoids memory swapping for this program */
54 mlockall(MCL_CURRENT
|MCL_FUTURE
);
56 /* create semaphore */
57 rt_sem_create(&semGlobal1
,"semaphore1",0,S_FIFO
);
58 rt_sem_create(&semGlobal2
,"semaphore2",1,S_FIFO
);
60 /* create the two tasks */
61 rt_task_create(&t1
, "task1", 0, 1, 0);
62 rt_task_create(&t2
, "task2", 0, 1, 0);
64 /* start the two tasks */
65 rt_task_start(&t1
, &taskOne
, 0);
66 rt_task_start(&t2
, &taskTwo
, 0);