Re: [musl] Re: [RFC PATCH] x86/vdso/32: Add AT_SYSINFO cancellation helpers
From: Ingo Molnar
Date: Fri Mar 11 2016 - 04:34:05 EST
* Rich Felker <dalias@xxxxxxxx> wrote:
> No, it doesn't work. Cancellability of the target thread at the time
> of the cancellation request (when you would decide whether or not to
> send the signal) has no relation to cancellability at the time of
> calling the cancellation point. Consider 2 threads A and B and the
> following sequence of events:
>
> 1. A has cancellation enabled
> 2. B calls pthread_cancel(A) and sets sticky pending signal
> 3. A disables cancellation
> 4. A calls cancellation point and syscall wrongly gets interrupted
As I (tried to!) describe it when describing the cancellation signal, if a
cancellation signal is in flight, it must be waited for in the unlikely event of
cancellation being disabled in the small window where the signal is sent.
So in your above example, it would do:
> 1. A has cancellation enabled
> 2. B calls pthread_cancel(A) and sets sticky pending signal
> 3. A disables cancellation
3b. Notices that cancellation request is pending and waits for it
and clears the sticky signal.
4. A calls cancellation point and syscall correctly executes
5. Once A enables cancellation again, the cancellation propagates.
So I still see no problem.
> This can be solved with more synchronization in pthread_cancel and
> pthread_setcancelstate, but it seems costly. [...]
An active signal round trip in itself is very costly (thousands of cycles), a
thread exit is tens of thousands of cycles, and this is a 'slow path' anyway, and
the window is small in any case.
It's just a correctness synchronization to make sure no sticky signal is pending,
not a real performance concern in practice.
Thanks,
Ingo