c++通过异步asyn执行任务,wait_for监督进度

 c++通过异步asyn执行任务,wait_for监督进度。

其中startSimulation是ClassName的成员函数,taskManage是startSimulation的参数。

任务启动后,每5秒检查执行进度。

//lanuch task and get result future
auto rf = std::async(std::launch::async, &ClassName::startSimulation, this, taskManage);
//check if the task has finished every 5 second
while (rf.wait_for(std::chrono::seconds(5))== std::future_status::timeout)  
{
    std::cout << taskManage->simCellNum << "/" << totSimNum << std::endl;
}

posted @ 2022-08-21 10:12  Oliver2022  阅读(77)  评论(0编辑  收藏  举报