Timeout for thread.join()

前端 未结 5 2201
暗喜
暗喜 2020-12-01 15:44

Is it possible to set a timeout for a call to std::thread::join()? I want to handle the case in which the thread is taking too long to run, or terminate the th

5条回答
  •  粉色の甜心
    2020-12-01 16:17

    Instead of using threads explicitly you can use std::async() to provide you with a std::future<> and you can do timed waits on the std::future:

    http://en.cppreference.com/w/cpp/thread/future/wait_for

提交回复
热议问题