Home  >  Q&A  >  body text

c++ - Boost 开出来的线程怎么捕捉 Ctrl - c

如题,我用 boost::thread 开了一个线程,线程就做循环打印吧。但是这个程序跑起来以后,按 ctrl-c,并不会立即退出,而要等挺长一段时间。

请问怎么使得这个线程能够马上响应呢?

PHP中文网PHP中文网2765 days ago748

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 12:08:28

    ctrl+c will send a SIGINT signal. boost::thread may need to complete some resource cleanup work before exiting. You can also handle SIGINT yourself. However, it is not recommended to use signals. Use condition variables under Linux. Both MESSAGE and EVENT can do this under Windows. There is a better way to use condition variables in C++11 (boost’s thread library has entered the 11 standard)

    reply
    0
  • Cancelreply