public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
To: Richard Weinberger <richard.weinberger@gmail.com>
Cc: Richard Weinberger via Libc-help <libc-help@sourceware.org>,
	linux-man <linux-man@vger.kernel.org>
Subject: Re: Clarification of pthread_cleanup_push() needed
Date: Wed, 22 Apr 2020 01:43:21 +0200	[thread overview]
Message-ID: <87r1wgo15y.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: <CAFLxGvzGyerUxinHxL=Rpqnm6wb3uTq+gjvL=_af4QzkOx3GHQ@mail.gmail.com> (Richard Weinberger's message of "Wed, 22 Apr 2020 00:48:28 +0200")

* Richard Weinberger:

> Well, this manpage does not talk much about the cleanup routine, except for
> "Consequently, clean-up handlers cease to be useful", which is clear as mud.

I think this refers to the fact that pthread_cleanup_push and
pthread_cleanup_pop are not necessarily async-cancel-safe.

> Back to the cleanup routine, with asynchronous cancellation:
> - it must not use any function which might got interrupted by cancel,
> - it may only use async-signal-safe function, except long jumps.
>
> Is this correct?

I think there are no restrictions on the cleanup handler *contents*
due to asynchronous cancellation.  The restrictions are on the code
that is interrupted.

You need to find a way to safely register them.  Code compiled by GCC
with -fexceptions and -fasynchronous-unwind-tables should work,
though.  In that case, the cleanup handler is not explicitly
registered, but implicitly identified by the region of code within
which the program counter is located during asynchronous cancellation.

> To give you some background, I'm porting an application to NPTL
> which comes from an operating system where cancelling threads and
> automatic cleanup is the way to go.

Do you have a list of functions that need to be async-cancel-safe for
this purpose?

      reply	other threads:[~2020-04-21 23:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 20:35 Clarification of pthread_cleanup_push() needed Richard Weinberger
2020-04-21 21:41 ` Florian Weimer
2020-04-21 22:04   ` Richard Weinberger
2020-04-21 22:12     ` Florian Weimer
2020-04-21 22:48       ` Richard Weinberger
2020-04-21 23:43         ` Florian Weimer [this message]

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=87r1wgo15y.fsf@mid.deneb.enyo.de \
    --to=fw@deneb.enyo.de \
    --cc=libc-help@sourceware.org \
    --cc=linux-man@vger.kernel.org \
    --cc=richard.weinberger@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox