退出 TBB 应用程序(任务调度程序)
我目前正在使用线程构建块来启动我的最新应用程序,并使用任务调度程序。
如果我的其中一项任务遇到退出程序的原因:
1.) 如何告诉所有其他任务返回?
2.) 如何在主线程中验证所有其他任务已返回,以便我可以安全地退出应用程序?
谢谢!
I'm currently using threading building blocks to start my newest application, using the task scheduler.
If one of my tasks encounters a reason to exit the program:
1.) How can I tell all the other tasks to return?
2.) How can I verify in the main thread that all other tasks have returned, so I can safely exit the application?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题的第一部分已经得到解答,您可以使用任务取消来停止任务不再被安排执行。例如:
在上面的例子中,由于是同步类型的API,主线程将照常等待所有任务终止。但如果您的问题暗示有异步运行的任务,请考虑使用低级 TBB 调度程序 API< /a> 或高级tbb::task_group 例如:
最后,还有正在阻止终止预览功能(搜索 TBB_PREVIEW_WAITING_FOR_WORKERS),如果您不仅需要等待任务完成执行,还需要等待 TBB 工作线程终止,这将有所帮助。
The first part of the question was answered already, you can use task cancellation to stop the task from being scheduled for execution. E.g.:
In the example above, the main thread will wait for all the tasks to terminate as usual since it is synchronous type of API. But if your question implies that there are asynchronously running tasks, consider using low-level TBB scheduler API or high-level tbb::task_group like:
And finally, there is blocking termination preview feature (search for TBB_PREVIEW_WAITING_FOR_WORKERS) which would help if you need not only wait for the tasks to finish execution but also wait when TBB workers terminate.
有许多函数取消任务和检查取消。环顾四周……你会发现更多。
There are many functions to cancel tasks and check for cancellation. Look around...you'll find more.