how to deal with thread-specific data in signal handler?

how to deal with thread-specific data in signal handler?

Post by Chris Friese » Wed, 28 May 2003 12:25:58



I've got a problem.  I want to get at thread-specific data in a signal handler.

A couple points:

1) pthread_getspecific() is not on the list of async-safe functions for susv2 or
for posix

2) Xavier Leroy, original author of linuxthreads, has written code that uses
pthread_getspecific() in a signal handler, and has stated "I can't think of any
reasonable implementation of pthread_getspecific() that would not be
async-signal safe, though."

3) I can find no documentation stating that pthread_getspecific() is async-safe
on linux.

So, is it safe or not?  Can anyone give or point to a definitive answer?

Chris

--
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986

 
 
 

how to deal with thread-specific data in signal handler?

Post by Paul Pluzhniko » Thu, 29 May 2003 00:03:03



> 2) Xavier Leroy, original author of linuxthreads, has written code that uses
> pthread_getspecific() in a signal handler, and has stated "I can't think of any
> reasonable implementation of pthread_getspecific() that would not be
> async-signal safe, though."

Yet his own implementation doesn't work correctly, if sigaltstack()
is used to switch to a different stack while handling the signal.

Quote:> So, is it safe or not?  

No.

Quote:> Can anyone give or point to a definitive answer?

It is trivial to construct a test case that proves negative answer
by having a (non-main) thread set things up with sigaltstack and
then handle some signal.

However, with i686 compilations of glibc, which use %gs rather than
%esp to access the thread descriptor, I think you'll be "safe".

This is also quite likely to work on other UNICes, but may not work
on some ;-(

Cheers,
--
In order to understand recursion you must first understand recursion.