catching SIGINT in a multithreaded program

后端 未结 1 1970
北荒
北荒 2020-12-15 12:32

I am writing a multithreaded program where I want to handle a possible Ctrl-C command from the user to terminate execution. As far as I know there is no guarantee

相关标签:
1条回答
  • 2020-12-15 13:08

    You can block signals from the calling thread with pthread_sigmask().

    And, as the blocked signals are inherited to newly created threads, you can block SIGINT in the main thread, then launch your other threads, and then unblock it in the main thread, if that is preferable.

    0 讨论(0)
提交回复
热议问题