public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Clarification of pthread_cleanup_push() needed
@ 2020-04-21 20:35 Richard Weinberger
  2020-04-21 21:41 ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Weinberger @ 2020-04-21 20:35 UTC (permalink / raw)
  To: linux-man; +Cc: libc-help

Hi!

Using pthread_cleanup_push() it is possible to register a cleanup
routine which will get
called upon thread cancellation.
I have a hard time to understand what exactly this routine allowed to
do and what not.

The manpage states:
"A clean-up handler is a function that is automatically executed when
a thread is
canceled (or in various other circumstances described below); it
might, for example,
unlock a mutex so that it becomes available to other threads in the process."

https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cleanup_push.html
even has an example with pthread_mutex_unlock() in the cleanup
function.

But NPTL implements thread cancellation with signals, if I'm not
completely mistaken
the cleanup routine will run in signal context then.
So only async-signal-safe functions are good to use.
pthread_mutex_unlock() is not.

With my (limited) understanding of the current NPTL implementation I'd
say a cleanup routine
might only use async-signal-safe functions, except long jumps.

Can you please clarify?
And can we please state this more precisely in the manpage?

-- 
Thanks,
//richard

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-04-21 23:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).