All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] race condition when creating and deleting VxWorks tasks in xenomai-forge
@ 2014-02-02 20:37 Matthias Schneider
  2014-02-03 11:03 ` Philippe Gerum
  0 siblings, 1 reply; 4+ messages in thread
From: Matthias Schneider @ 2014-02-02 20:37 UTC (permalink / raw)
  To: xenomai@xenomai.org

Hi all, there seems to be a race condition in the VxWorks skin in xenomai-forge 
when creating and deleting tasks in rapid succession. The problem seems to be the 
adding and removing of tasks to wind_task_list in task_trampoline() and 
task_finalizer().

When creating a task, before returning a handle to the created task to the 
application, calling threadobj_start() from taskActivate() will wait for 
&thobj->barrier by calling wait_on_barrier(). This condition is triggered from 
the newly created task via task_trampoline() calling threadobj_prologue(). 
Having unblocked taskActivate(), the creating task/thread will return to the 
calling application, which in turn can delete the task in quick succession. 
Deleting the task will trigger the execution of task_finalizer, which will try 
to remove the task from wind_task_table. However, due to specific timing 
situations, it may be possible  that the started task has not yet added itself 
to the list (it may still be "just" leaving threadobj_prologue()), leading to
a segmentation fault. This behavior can be easily reproduced by adding a delay
in task_trampoline() at the following location in taskLib.c:

ret = __bt(threadobj_prologue(&task->thobj, task->name));

usleep(100000);

write_lock_nocancel(&wind_task_lock);
pvlist_append(&task->next, &wind_task_list);
write_unlock(&wind_task_lock);


writing a simple test application that simply calls

SEM_ID tid = taskSpawn(name, 50, 0, 0, task, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
taskDelete(tid);

will then reliably demonstrate the issue.

Moving the last three lines appending the task to the list above threadobj_prologue() 
seems to fix the issue, although I am not 100% sure about possible side effects.

Thanks in advance for commenting my issue,
regards,

Matthias


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-02-06  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-02 20:37 [Xenomai] race condition when creating and deleting VxWorks tasks in xenomai-forge Matthias Schneider
2014-02-03 11:03 ` Philippe Gerum
2014-02-04 19:12   ` Matthias Schneider
2014-02-06  9:51     ` Philippe Gerum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.