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 @   Oliver2022  阅读(85)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示