This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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]

Libc thread cancelation safety?


I have noticed that printf in glibc (glibc 2.3.5, i386) is not pthread
cancellation safe, though printf on Solaris is cancellation safe.  
Specifically, canceling a thread in printf leads to deadlock.

What should one expect regarding cancelation safety in standard
libraries?  Is this a bug in glibc?

I haven't done a lot of testing of other functions in the standard
library, so I don't know if this affects more than just printf and
friends.

Working around it is easy, but I'm not sure how many functions one needs
to do this for...'Everything' might be a bit tedious.

static int safe_printf(char *fmt, ...)
{
    va_list ap;
    int cancelstate;
    int ret, status;

    va_start(ap, fmt);
    status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancelstate);
    ret = vprintf(fmt, ap);
    status = pthread_setcancelstate(cancelstate, &cancelstate);
    return (ret);
}

#define printf safe_printf

I have a test program if anyone is interested.

		--Dean



-- 
Av8 Internet   Prepared to pay a premium for better service?
www.av8.net         faster, more reliable, better service
617 344 9000   



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