1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-07 06:43:00 +03:00

nptl: Set cancellation type and state on pthread_exit (BZ #28267)

It is required by POSIX XSH 2.9.5 Thread Cancellation under the
heading Thread Cancellation Cleanup Handlers.

Checked x86_64-linux-gnu.
This commit is contained in:
Adhemerval Zanella
2025-07-09 16:18:09 -03:00
parent 6afece738c
commit 4dc393f13e
3 changed files with 148 additions and 1 deletions

View File

@@ -268,7 +268,20 @@ __do_cancel (void *result)
self->result = result;
/* Make sure we get no more cancellations. */
atomic_fetch_or_relaxed (&self->cancelhandling, EXITING_BITMASK);
int oldval = atomic_load_relaxed (&self->cancelhandling);
int newval;
do
{
/* It is required by POSIX XSH 2.9.5 Thread Cancellation under the
heading Thread Cancellation Cleanup Handlers and also avoid further
cancellation wrapper to act on cancellation. */
newval = oldval | CANCELSTATE_BITMASK | EXITING_BITMASK;
newval = newval & ~CANCELTYPE_BITMASK;
if (oldval == newval)
break;
}
while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling,
&oldval, newval));
__pthread_unwind ((__pthread_unwind_buf_t *)
THREAD_GETMEM (self, cleanup_jmp_buf));