I have created a pthread, and installed a signal handler inside that, same way as we do in main( )
function. The thread\'s signal handler is a separate function
The one problem with you code that nobody has mentioned yet is that, while signal blocking (and delivery, if you use pthread_kill
or raise
) are per-thread, signal handlers are per-process. This means they're a very bad mechanism for inter-thread communication, especially if your code will ever be used as library code, since it's extremely bad behavior for a library to alter the caller's signal handlers.
Also note that using signal handlers for communication between threads has sub-optimal performance compared to other methods of thread signaling like condition variables or barriers, because there's at least one additional user-kernel-user transition (when the signal handler returns).