同步操作将从 Gitee 极速下载/cpp-taskflow 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// The program demonstrates how to create asynchronous task// from an executor and a subflow.#include <taskflow/taskflow.hpp>int main() {tf::Executor executor;// create asynchronous tasks from the executor// (using executor as a thread pool)tf::Future<std::optional<int>> future1 = executor.async([](){std::cout << "async task 1 returns 1\n";return 1;});executor.silent_async([](){ // silent async task doesn't returnstd::cout << "async task 2 does not return (silent)\n";});// create asynchronous tasks with names (for profiling)executor.named_async("async_task", [](){std::cout << "named async task returns 1\n";return 1;});executor.named_silent_async("silent_async_task", [](){std::cout << "named silent async task does not return\n";});executor.wait_for_all(); // wait for the two async tasks to finish// create asynchronous tasks from a subflow// all asynchronous tasks are guaranteed to finish when the subflow joinstf::Taskflow taskflow;std::atomic<int> counter {0};taskflow.emplace([&](tf::Subflow& sf){for(int i=0; i<100; i++) {sf.silent_async([&](){ counter.fetch_add(1, std::memory_order_relaxed); });}sf.join();// when subflow joins, all spawned tasks from the subflow will finishif(counter == 100) {std::cout << "async tasks spawned from the subflow all finish\n";}else {throw std::runtime_error("this should not happen");}});executor.run(taskflow).wait();return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。