Boost Thread - How to acknowledge interrupt

前端 未结 1 450
臣服心动
臣服心动 2021-02-07 07:49

I have blocking task which will be performed by find_the_question() function. However, I do not want thread executing this function take more than 10 seconds. So in case it take

1条回答
  •  清酒与你
    2021-02-07 08:27

    For using boost::thread::interrupt(), you have to use boost::thread::sleep() for it to work.

    A running thread can be interrupted by invoking the interrupt() member function of the corresponding boost::thread object. When the interrupted thread next executes one of the specified interruption points (or if it is currently blocked whilst executing one) with interruption enabled, then a boost::thread_interrupted exception will be thrown in the interrupted thread. If not caught, this will cause the execution of the interrupted thread to terminate. As with any other exception, the stack will be unwound, and destructors for objects of automatic storage duration will be executed

    Predefined interruption points:

    The following functions are interruption points, which will throw boost::thread_interrupted if interruption is enabled for the current thread, and interruption is requested for the current thread:

    boost::thread::join()
    boost::thread::timed_join()
    boost::condition_variable::wait()
    boost::condition_variable::timed_wait()
    boost::condition_variable_any::wait()
    boost::condition_variable_any::timed_wait()
    boost::thread::sleep()
    boost::this_thread::sleep()
    boost::this_thread::interruption_point()
    

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