Hi i have a problem in my code the rt_sem_create calls returns a negative
value i.e. -17
THat is semaphore creation fails? Why is it so?
Here is the code that i am trying to execute. I have created semaphore in
the main routine.
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <native/task.h>
#include <native/timer.h>
#include <native/sem.h>
RT_TASK task1;
RT_TASK task2;
RT_SEM sem1;
int i,res;
void low_task(void *arg)
{
printf("Inside the low priority task\n");
rt_sem_p(&sem1,300000000);
printf("I have the semaphore released by the high task\n");
}
void high_task(void *arg)
{
printf("Inside the high priority task \n");
res =rt_sem_p(&sem1,TM_INFINITE);
printf("%d\n", res);
if(res == 0)
{
printf("Semaphore Acquired by High task");
}
rt_task_sleep(3000000000);
rt_sem_v(&sem1);
printf("I have released the semaphore : High\n");
}
int main()
{
int res;
mlockall(MCL_CURRENT|MCL_FUTURE);
rt_task_create(&task2, "High Priority Task2", 0, 98, 0);
rt_task_create(&task1, "Low Priority Task1", 0, 5, 0);
res = rt_sem_create(&sem1, "Semaphore1", 0, S_PRIO);
printf("%d\n",res);
rt_task_start(&task2, &high_task, NULL);
rt_task_start(&task1, &low_task, NULL);
pause();
rt_task_join(&task1);
rt_task_join(&task2);
}
_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help