update ex11
[des2015.git] / mart / xenomai / ex03 / ex03b.c
1 #include <stdio.h>
2 #include <signal.h>
3 #include <unistd.h>
4 #include <sys/mman.h>
5
6 #include <native/task.h>
7 #include <native/timer.h>
8 #include <native/sem.h>
9
10 #include <rtdk.h>
11
12 #define ITER 10
13
14 static RT_TASK t1;
15 static RT_TASK t2;
16 RT_SEM sem;
17
18 int global = 0;
19
20 void taskOne(void *arg)
21 {
22 int i;
23 for (i=0; i < ITER; i++)
24 {
25 rt_sem_p(&sem, TM_INFINITE);
26 rt_printf("I am taskOne and global = %d................\n", ++global);
27 rt_sem_v(&sem);
28 }
29 }
30
31 void taskTwo(void *arg)
32 {
33 int i;
34 for (i=0; i < ITER; i++)
35 {
36 rt_sem_p(&sem, TM_INFINITE);
37 rt_printf("I am taskTwo and global = %d----------------\n", --global);
38 rt_sem_v(&sem);
39 }
40 }
41
42 int main(int argc, char* argv[])
43 {
44 /* Perform auto-init of rt_print buffers if the task doesn't do so */
45 rt_print_auto_init(1);
46
47 /* Avoids memory swapping for this program */
48 mlockall(MCL_CURRENT|MCL_FUTURE);
49
50 /* create the two tasks */
51 rt_task_create(&t1, "task1", 0, 1, 0);
52 rt_task_create(&t2, "task2", 0, 1, 0);
53
54 /* create semaphore and start in blocked mode */
55 rt_sem_create(&sem, "sem", 0, S_FIFO);
56
57 /* start the two tasks */
58 rt_task_start(&t1, &taskOne, 0);
59 rt_task_start(&t2, &taskTwo, 0);
60
61 /* release the semaphore */
62 rt_sem_v(&sem);
63 return 0;
64 }