This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

pthread_clear_exit_np()


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

--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]