Linux.com

Home Linux Community Forums Programming and Development Software Development Sending a signal to a pthread with sigqueue

Sending a signal to a pthread with sigqueue

Link to this post 23 Feb 10

Dear Linux experts,
Is it possible to send a signal to a pthread with sigqueue() ?
The argument of the function is a process ID and not a thread ID.
I can use pthread_kill() but I need to send an accompanying value as in sigqueue().
Thanks,
Hiromichi

Link to this post 27 Feb 10

This is not an insurmountable problem, using pthread_kill() to signal a thread with data. AFAIK, using sigqueue() is not thread safe. It should only be handled in the main thread of the program. However, you can create an associative array of structures that associate a thread id with the data you wish to communicate. Then, the thread's signal handler can look at the associated with its tid and act accordingly. FWIW, you could try to use the thread id in place of a process id for sigqueue(). I don't know if that would work, and it might in some systems, but not in others. Caveat programmer! :-)

Link to this post 28 Feb 10

Hi woboyle,
Thank you very much for your reply.
On Ubuntu linux, sigqueue with thread id does not work.
My intention was to have 4 slave threads send the same signal to the master thread asyncronously so accessing the master's associtive structure by the slaves must be carried out with a mutex.
So for lack of simpler solutions, I will have 4 slaves send 4 different signals because only information I need to send with the signal is from which slave the signal is originating.
Hiromichi

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board