Signal handling among pthreads Signal handling among pthreads multithreading multithreading

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:

  1. 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.
  2. Send a signal to a process group: The signal will be delivered to all processes in the group.
  3. 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().