rt_task_join() call hangs in shared lib destructor
Quoted 30 lines
Quoted 10 lines · Gilles Chanteperdrix
Quoted 8 lines · Mauro Salvini
Quoted 4 lines
It looks like a typical
pthread_joindeadlock. The thread you are joining is locked on a pthread mutex, that some other thread (I would say, the one callingpthread_join) has. It can not work. You should not callpthread_joinwhile holding a mutex.Yes, it looks like this, but I don't use any mutex in my task. It looks like
dlclose()locks a mutex used also bypthread_join()(that was called into shared object destructor), and here is deadlock. But executing realtime task as normal thread does not raise this issue.Quoted 5 lines
The trace you sent clearly shows that the problem happens because
rt_task_trampolinecallspthread_exit. In your tests with rt_task_shadow/pthread_create, did you try to usepthread_exit? Or could you try replacing the call topthread_exitinrt_task_trampolinewith a return?Answering to myself: no, in your examples you did not use
pthread_exit, that is the difference with thert_task_createcase.So, could you try the following patch?
src/skins/native/task.c +0
-0@@ -113,7 +113,7 @@ static void *rt_task_trampoline(void *cookie)fail:
Quoted 7 lines
-
pthread_exit((void *)err);
+ return (void *)err;
}int rt_task_create(RT_TASK *task,
Yes, patch works: rt_task_join works correctly now.
By the way, before apply patch, as you suggest in your penultimate mail, I tried to use pthread_exit in tests with rt_task_shadow/pthread_create: application hangs as with rt_task_create().
So, I deduce that pthread_exit must not be called into shared object threads/tasks, to avoid joining hangs when object destructor was called. Is this a libc bug or is the normal way of coding?
Thank you very much Gilles for your precious help! Regards
Quoted 43 lines · Mauro Salvini
Quoted 28 lines
Quoted 11 lines · Gilles Chanteperdrix
Quoted 10 lines · Mauro Salvini
Quoted 5 lines
It looks like a typical
pthread_joindeadlock. The thread you are joining is locked on a pthread mutex, that some other thread (I would say, the one callingpthread_join) has. It can not work. You should not callpthread_joinwhile holding a mutex.Yes, it looks like this, but I don't use any mutex in my task. It looks like
dlclose()locks a mutex used also bypthread_join()(that was called into shared object destructor), and here is deadlock. But executing realtime task as normal thread does not raise this issue.Quoted 5 lines
The trace you sent clearly shows that the problem happens because
rt_task_trampolinecallspthread_exit. In your tests with
rt_task_shadow/pthread_create, did you try to usepthread_exit? Or could you try replacing the call topthread_exitinrt_task_trampolinewith a return?Answering to myself: no, in your examples you did not use
pthread_exit, that is the difference with thert_task_createcase.So, could you try the following patch?
src/skins/native/task.c +0
-0
b/src/skins/native/task.c@@ -113,7 +113,7 @@ static void *rt_task_trampoline(void *cookie)Quoted 7 lines
fail:
-
pthread_exit((void *)err); + return (void *)err; }int rt_task_create(RT_TASK *task,
Yes, patch works:
rt_task_joinworks correctly now.By the way, before apply patch, as you suggest in your penultimate mail, I tried to use
pthread_exitin tests with rt_task_shadow/pthread_create: application hangs as withrt_task_create().
Quoted 5 lines
So, I deduce that
pthread_exitmust not be called into shared object threads/tasks, to avoid joining hangs when object destructor was called. Is this a libc bug or is the normal way of coding?Thank you very much Gilles for your precious help! Regards
It definitely has nothing to do with Xenomai, whether this is a glibc bug or not, only glibc maintainers can answer.
But the workaround is easy, just create a function to shutdown the thread in the .so object. And call this function before dlclose.
Signature · 1 line
Gilles.