* Richard Weinberger: > On Tue, Apr 21, 2020 at 11:41 PM Florian Weimer <fw@xxxxxxxxxxxxx> wrote: >> >> * Richard Weinberger via Libc-help: >> >> > But NPTL implements thread cancellation with signals, if I'm not >> > completely mistaken the cleanup routine will run in signal context >> > then. >> >> Deferred cancellation only occurs in signal context if the >> cancellation is acted upon from within a signal handler. For the >> signal handler case, whether cancellation handlers are restricted to >> async-signal-safe function calls depends on the type of signal (some >> are synchronous, not asynchronous) and what is interrupted by the >> signal (for asynchronous signals). >> >> Asynchronous cancellation has even more constraints than asynchronous >> signal safety, but it is rarely used. > > I should have noted that I'm using asynchronous cancellation. > Which constraints are these? See pthread_setcanceltype(3): Functions that can be safely asynchronously canceled are called async-cancel-safe functions. POSIX.1-2001 and POSIX.1-2008 require only that pthread_cancel(3), pthread_setcancelstate(), and pthread_setcanceltype() be async-cancel-safe. In general, other library functions can't be safely called from an asynchronously cancelable thread. The manual pages and the glibc manual also contain information about AC-safety, but you cannot rely on them. They depend on implementation details which may change within release branches.