All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Mauro Salvini <mauro.salvini@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] rt_task_join() call hangs in shared lib destructor
Date: Thu, 28 Apr 2011 15:33:16 +0200	[thread overview]
Message-ID: <4DB96C9C.9000005@domain.hid> (raw)
In-Reply-To: <31508283.431303994486968.JavaMail.SYSTEM@pc-msalvini>

Mauro Salvini wrote:
>> Gilles Chanteperdrix wrote:
>>> Mauro Salvini wrote:
>>>>> 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?
>> 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?
>> 
>> diff --git a/src/skins/native/task.c b/src/skins/native/task.c 
>> index be4ea2c..70ba6f7 100644 --- a/src/skins/native/task.c +++
>> b/src/skins/native/task.c @@ -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,
>> 
>> 
> 
> 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

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.

-- 
					    Gilles.


  reply	other threads:[~2011-04-28 13:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <33469777.411303994184796.JavaMail.SYSTEM@pc-msalvini>
2011-04-28 12:41 ` [Xenomai-help] rt_task_join() call hangs in shared lib destructor Mauro Salvini
2011-04-28 13:33   ` Gilles Chanteperdrix [this message]
     [not found] <27947354.221303982673109.JavaMail.SYSTEM@pc-msalvini>
2011-04-28  9:26 ` Mauro Salvini
2011-04-28 11:06   ` Gilles Chanteperdrix
2011-04-28 11:45     ` Gilles Chanteperdrix
     [not found] <30435812.01303909424265.JavaMail.SYSTEM@pc-msalvini>
2011-04-27 13:06 ` Mauro Salvini
     [not found] <11882793.141303825258312.JavaMail.SYSTEM@pc-msalvini>
2011-04-26 13:50 ` Mauro Salvini
2011-04-26 18:06   ` Gilles Chanteperdrix
2011-04-27 16:59   ` Gilles Chanteperdrix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DB96C9C.9000005@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=mauro.salvini@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.