Signal handling among pthreads
- Can signals [be] sent to all pthreads [and] be handled by more than one pthread at the same time?
Not at the same time. These are the possibilities:
- Send a signal to a process (
kill()
): In this case, any thread listening for the signal can receive it, but just one will do it. - Send a signal to a process group: The signal will be delivered to all processes in the group.
- Send a signal to a specific thread (
pthread_kill()
): now you are sending it to a specific thread ID.
Prototype:
int pthread_kill(pthread_t thread, int sig);
In your case, I think the only way to deliver the signal to all threads is iterating along all your thread ids to send the signal with pthread_kill()
.