All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: xenomai-core <xenomai@xenomai.org>
Subject: Re: [Xenomai-core] [Xenomai-git] Jan Kiszka : native: Rework handling of pthread carrier thread
Date: Sat, 05 Jun 2010 21:22:20 +0200	[thread overview]
Message-ID: <4C0AA3EC.7040106@domain.hid> (raw)
In-Reply-To: <4C0AA2F0.6050201@domain.hid>

[-- Attachment #1: Type: text/plain, Size: 3654 bytes --]

Gilles Chanteperdrix wrote:
> Jan Kiszka wrote:
>> Gilles Chanteperdrix wrote:
>>> Jan Kiszka wrote:
>>>> Gilles Chanteperdrix wrote:
>>>>> Jan Kiszka wrote:
>>>>>> Gilles Chanteperdrix wrote:
>>>>>>> GIT version control wrote:
>>>>>>>> Module: xenomai-jki
>>>>>>>> Branch: for-upstream
>>>>>>>> Commit: 0352b068600bd4ef3172c8a42416badbcdad32ca
>>>>>>>> URL:    http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=0352b068600bd4ef3172c8a42416badbcdad32ca
>>>>>>>>
>>>>>>>> Author: Jan Kiszka <jan.kiszka@domain.hid>
>>>>>>>> Date:   Wed Apr 28 15:08:11 2010 +0200
>>>>>>>>
>>>>>>>> native: Rework handling of pthread carrier thread
>>>>>>>>
>>>>>>>> This patch improves two pitfalls of libnative's interaction with
>>>>>>>> underlying pthreads:
>>>>>>>>
>>>>>>>> First, it tries to detect double deletions (cancellations or joinings)
>>>>>>>> of pthreads and report them via an error code. This reduces the risk to
>>>>>>>> trigger a SIGSEGV accessing meanwhile released pthread objects. And
>>>>>>>> second, it properly detaches joinable pthreads when they are deleted
>>>>>>>> instead. This properly releases the pthread resources.
>>>>>>> I really do not understand that. What is the point of creating a
>>>>>>> joinable thread if you do not want to join it once it has been canceled?
>>>>>>>
>>>>>> Keep in mind that there is no pthread_cancel equivalent in the native
>>>>>> API. Moreover, even POSIX has pthread_detach so that you are not forced
>>>>>> to join every joinable thread. I could imagine that one may want to use
>>>>>> this fot error cleanups. But first of all this is about improving the
>>>>>> API consistency and fault tolerance.
>>>>> I have no strong opinion on that matter, but it looks to me like the
>>>>> "joinable" stuff in the native API is made to look like the posix
>>>>> equivalent, following the principle of least surprise. So, since posix
>>>>> requires joining a thread after canceling, it should be necessary to
>>>>> join a thread after deleting it.
>>>> The problem is that there is no direct equivalent to rt_task_delete with
>>>> pthread. What comes closest is pthread_cancel + pthread_detach (where
>>>> required). Still, rt_task_delete is synchronous, pthread_cancel not.
>>> rt_task_delete looks to me like really equivalent to pthread_cancel.
>> rt_task_delete was once designed to sweep a task object, not just to
>> terminate its runnable context (thought that's hard - if not impossible
>> - to maintain across process boundaries).
>>
>> While you can join a canceled pthread, you can't do this reliably with a
>> deleted task. It happened to work if you were already holding a (then
>> outdated) handle. But, officially, the lifetime of a tasks ends when
>> rt_task_delete returns. No service is supposed to accept any further
>> requests regarding this object afterwards. Making rt_task_join an
>> exception may raise confusion.
>>
>>> I do not think rt_task_delete is supposed to be synchronous (it looks to
>>> me it is not if you delete a thread running on another cpu than the
>>> current one). And pthread_detach is not synchronous either. The only way
>>> to wait for a thread deletion is to use pthread_join/rt_task_join.
>>>
>> It is synchronous /wrt the validity of the task object which includes
>> the schedulable part in kernel space. The carrier thread is in pthread
>> hands, but Xenomai is out of the game when rt_task_delete returned.
> 
> Not being able to join a deleted task undermines seriously the utility
> of rt_task_join... What is it useful for, then?

See the doc: You join or delete, but not both.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

  reply	other threads:[~2010-06-05 19:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1OKZdD-0003ml-45@domain.hid>
2010-06-04 19:48 ` [Xenomai-core] [Xenomai-git] Jan Kiszka : native: Rework handling of pthread carrier thread Gilles Chanteperdrix
2010-06-04 23:58   ` Jan Kiszka
2010-06-05 12:57     ` Gilles Chanteperdrix
2010-06-05 18:43       ` Jan Kiszka
2010-06-05 18:49         ` Gilles Chanteperdrix
2010-06-05 19:14           ` Jan Kiszka
2010-06-05 19:18             ` Gilles Chanteperdrix
2010-06-05 19:22               ` Jan Kiszka [this message]
2010-06-05 19:28                 ` Gilles Chanteperdrix
2010-06-05 20:46                   ` Jan Kiszka
2010-06-06 12:44                     ` Gilles Chanteperdrix
2010-06-18 18:59                       ` Jan Kiszka
2010-06-18 19:06                         ` Gilles Chanteperdrix
2010-06-18 20:17                           ` Jan Kiszka
2010-06-19 10:14                             ` Gilles Chanteperdrix
2010-06-19 11:52                               ` Jan Kiszka
2010-06-19 12:28                                 ` 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=4C0AA3EC.7040106@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=gilles.chanteperdrix@xenomai.org \
    --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.