This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
pthread_clear_exit_np()
- From: Luke Howard <lukeh at padl dot com>
- To: libc-alpha at sources dot redhat dot com
- Cc: opendce at opengroup dot org, freedce-devel at lists dot sourceforge dot net
- Date: Fri, 21 Apr 2006 12:08:41 +1000
- Subject: pthread_clear_exit_np()
- Reply-to: lukeh at padl dot com
- Versions: dmail (bsd44) 2.6d/makemail 2.10
The OSF DCE runtime implements its own exception handling which allows
pthread cancels to be caught. It does this by doing a non-local goto
out of a cancellation handler. I appreciate that this behaviour is not
specified by POSIX.
To make this work with libc we need to "un-cancel" a thread. The
following function (API from AIX) appears to do the trick:
int pthread_clear_exit_np(void)
{
if (__dce_pthread_nptl) {
volatile struct pthread *pd = (struct pthread *)pthread_self();
int oldval;
int newval;
if (pd->tid <= 0)
return ESRCH;
if ((pd->cancelhandling & EXITING_BITMASK) == 0)
return EINVAL;
do {
oldval = pd->cancelhandling;
newval = oldval & ~(CANCELING_BITMASK | CANCELED_BITMASK | EXITING_BITMASK);
if (newval == oldval)
break;
} while (atomic_compare_and_exchange_bool_acq(&pd->cancelhandling, newval, oldval));
}
return 0;
}
Of course, using this in a third-party application is problematic as it
depends on internal glibc structures.
I know the chances of such an API being added to glibc are about nil, but
I thought I'd mention this anyway! :-)
cheers,
-- Luke
--