Signal handling in pthreads

后端 未结 3 1392
执笔经年
执笔经年 2020-11-30 00:37

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

3条回答
  •  失恋的感觉
    2020-11-30 01:31

    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).

提交回复
热议问题