M. Warner Losh wrote: > In message: <[EMAIL PROTECTED]> > Jamie Lokier <[EMAIL PROTECTED]> writes: > : Btw, unfortunately pthread_self() is not safe to call from signal > : handlers. > > And also often times meaningless, as signal handlers can run in > arbitrary threads...
That's usually the case, but sometimes it is useful. Some causes of signals are thread specific, or can be asked to be, and it's nice to know which thread is receiving them (e.g. thread specific timers, SIGIOs, write-protection SEGVs, and even sending messages with good old pthread_kill (same reason as kernel uses IPIs)). GCC's Boehm garbage collector uses pthread_self() from a signal handler. I've used gettid() in a signal handler on a few occasions. -- Jamie