Hey all,
I found that there is a task not created when I access my server(Xenomai) at
second time.
Because this task has already exist by rt_task_inquire API.
Finally, I found the problem in rt_task_delete(RT_TASK * task) API. When
rt_task_delete is called,
Information in variable task still exists.
So, to illustrate the problem, I wrote a test program as follow:
/************************************Start*************************************************/
#include <stdio.h>
#include <unistd.h>
#include <alchemy/task.h>
#define TASK_NUM 2
RT_TASK task[TASK_NUM];
RT_TASK_INFO task_info = {0};
char task_name[100] = {0};
void func(void *arg)
{
rt_task_suspend(NULL);
}
int main()
{
int i = 0;
memset(task, 0, TASK_NUM * sizeof(RT_TASK));
//create task
printf("first create task\n");
for(i = 0; i < TASK_NUM; i++)
{
if(rt_task_inquire(&task[i], &task_info) != 0)
{
memset(task_name, 0, sizeof(task_name));
sprintf(task_name, "task%d", i);
rt_task_spawn(&task[i], task_name, 0, 80, 0, func, (void *)i);
printf("create task%d, handle = %lu, thread = %lu\n", i,
task[i].handle, task[i].thread);
}
else
{
printf("exist task%d, handle = %lu, thread = %lu\n", i,
task[i].handle, task[i].thread);
}
}
rt_task_sleep(3*1000*1000*1000llu);
//delete task
printf("\ndelete task\n");
for(i = 0; i < TASK_NUM; i++)
{
rt_task_delete(&task[i]);
}
for(i = 0; i < TASK_NUM; i++)
{
printf("delete task%d, handle = %lu, thread = %lu\n", i,
task[i].handle, task[i].thread);
}
//create task again, inverted sequence
printf("\nsecond create task\n");
for(i = TASK_NUM - 1; i >= 0; i--)
{
if(rt_task_inquire(&task[i], &task_info) != 0)
{
memset(task_name, 0, sizeof(task_name));
sprintf(task_name, "task%d", i);
rt_task_spawn(&task[i], task_name, 0, 80, 0, func, (void *)i);
printf("create task%d, handle = %lu, thread = %lu\n", i,
task[i].handle, task[i].thread);
}
else
{
printf("exist task%d, handle = %lu, thread = %lu\n", i,
task[i].handle, task[i].thread);
}
}
rt_task_sleep(3*1000*1000*1000llu);
return 0;
}
/************************************End*************************************************/
The test program output:
/************************************Start*************************************************/
first create task
create task0, handle = 51377, thread = 140454644737792
create task1, handle = 52401, thread = 140454644668160
delete task
delete task0, handle = 51377, thread = 140454644737792
delete task1, handle = 52401, thread = 140454644668160
second create task
create task1, handle = 51377, thread = 140454644668160
exist task0, handle = 51377, thread = 140454644737792
/************************************End*************************************************/
I'm now manually memset task variable, but I still want to do it in the
xenomai library
to make more people less detours.
Best regards
_______________________________________________
Xenomai mailing list
[email protected]
https://xenomai.org/mailman/listinfo/xenomai