How to check if a std::async task is finished?

前端 未结 2 818
生来不讨喜
生来不讨喜 2021-02-07 00:43

In my graphics application I want to generate a batch meshes in another thread. Therefore I asynchrony call the member function using std::async.

ta         


        
2条回答
  •  孤独总比滥情好
    2021-02-07 01:06

    Use future::wait_for(). You can specify a timeout, and after that, get a status code.

    Example:

    task.wait_for(std::chrono::seconds(1));
    

    This will return future_status::ready, future_status::deferred or future_status::timeout, so you know the operation's status. You can also specify a timeout of 0 to have the check return immediately as soon as possible.

提交回复
热议问题