Libc thread cancelation safety?
Dean Anderson
dean@av8.com
Fri Mar 20 18:52:00 GMT 2009
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
More information about the Gcc-help
mailing list