Skip to contentSkip to conversation

rt_task_join() call hangs in shared lib destructor

Xenomai-help Mauro Salvini 2 participants 3 messages Apr 28, 2011 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 27947354.221303982673109.JavaMail.SYSTEM@pc-msalvini

#1 lore raw
Quoted 6 lines

It looks like a typical pthread_join deadlock. The thread you are joining is locked on a pthread mutex, that some other thread (I would say, the one calling pthread_join) has. It can not work. You should not call pthread_join while 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 by pthread_join() (that was called into shared object destructor), and here is deadlock. But executing realtime task as normal thread does not raise this issue.

Another strange behaviour: if task was not created with rt_task_create()-rt_task_start(), but becomes real time from a thread with rt_task_shadow(), it works properly.

Summarizing:
- create task with rt_task_create()-rt_task_start() and join it in shared object destructor with rt_task_join() -> deadlock
- create a thread with pthread_create(), make it real-time with rt_task_shadow() and join it in destructor with rt_task_join() -> works fine
- create a thread with pthread_create(), join it in destructor with pthread_join() -> works fine

Same behaviors on kernel 2.6.37 with Xenomai 2.5.6 Ipipe 2.9-00 .

Quoted 2 lines

If this is not the issue, would you please take the time to post a self-contained test case which I can run to reproduce the issue?

Was attached on my first mail, I re-attach it to this mail. I also added 2nd and 3rd case explained above: you can select each case with three #defines into TestMod.c.

Many thanks, regards.

#2 lore raw
Quoted 10 lines · Mauro Salvini
Quoted 5 lines

It looks like a typical pthread_join deadlock. The thread you are joining is locked on a pthread mutex, that some other thread (I would say, the one calling pthread_join) has. It can not work. You should not call pthread_join while 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 by pthread_join() (that was called into shared object destructor), and here is deadlock. But executing realtime task as normal thread does not raise this issue.

The trace you sent clearly shows that the problem happens because rt_task_trampoline calls pthread_exit. In your tests with rt_task_shadow/pthread_create, did you try to use pthread_exit? Or could you try replacing the call to pthread_exit in rt_task_trampoline with a return?

Signature · 1 line
                                                                Gilles.
#3 lore raw
Quoted 10 lines · Gilles Chanteperdrix
Quoted 8 lines · Mauro Salvini
Quoted 4 lines

It looks like a typical pthread_join deadlock. The thread you are joining is locked on a pthread mutex, that some other thread (I would say, the one calling pthread_join) has. It can not work. You should not call pthread_join while 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 by pthread_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_trampoline calls pthread_exit. In your tests with rt_task_shadow/pthread_create, did you try to use pthread_exit? Or could you try replacing the call to pthread_exit in rt_task_trampoline with a return?

Answering to myself: no, in your examples you did not use pthread_exit, that is the difference with the rt_task_create case.

So, could you try the following patch?

src/skins/native/task.c +1 -1
index be4ea2c..70ba6f7 100644
@@ -113,7 +113,7 @@ static void *rt_task_trampoline(void *cookie)
 
       fail:
 
-	pthread_exit((void *)err);
+	return (void *)err;
 }
 
 int rt_task_create(RT_TASK *task,
Signature · 1 line
                                                                Gilles.