同步操作将从 Gitee 极速下载/cpp-taskflow 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// This example demonstrates how to use Taskflow to create// dynamic workload during execution.//// We first create four tasks A, B, C, and D. During the execution// of B, it uses flow builder to creates another three tasks// B1, B2, and B3, and adds dependencies from B1 and B2 to B3.//// We use dispatch and get to wait until the graph finished.// Do so is difference from "wait_for_all" which will clean up the// finished graphs. After the graph finished, we dump the topology// for inspection.//// Usage: ./subflow detach|join//#include <taskflow/taskflow.hpp>const auto usage = "usage: ./subflow detach|join";int main(int argc, char* argv[]) {if(argc != 2) {std::cerr << usage << std::endl;std::exit(EXIT_FAILURE);}std::string opt(argv[1]);if(opt != "detach" && opt != "join") {std::cerr << usage << std::endl;std::exit(EXIT_FAILURE);}auto detached = (opt == "detach") ? true : false;// Create a taskflow graph with three regular tasks and one subflow task.tf::Executor executor(4);tf::Taskflow taskflow("Dynamic Tasking Demo");// Task Aauto A = taskflow.emplace([] () { std::cout << "TaskA\n"; });auto B = taskflow.emplace(// Task B[cap=std::vector<int>{1,2,3,4,5,6,7,8}, detached] (tf::Subflow& subflow) {std::cout << "TaskB is spawning B1, B2, and B3 ...\n";auto B1 = subflow.emplace([&]() {printf(" Subtask B1: reduce sum = %d\n",std::accumulate(cap.begin(), cap.end(), 0, std::plus<int>()));}).name("B1");auto B2 = subflow.emplace([&]() {printf(" Subtask B2: reduce multiply = %d\n",std::accumulate(cap.begin(), cap.end(), 1, std::multiplies<int>()));}).name("B2");auto B3 = subflow.emplace([&]() {printf(" Subtask B3: reduce minus = %d\n",std::accumulate(cap.begin(), cap.end(), 0, std::minus<int>()));}).name("B3");B1.precede(B3);B2.precede(B3);// detach or join the subflow (by default the subflow join at B)if(detached) subflow.detach();});auto C = taskflow.emplace([] () { std::cout << "TaskC\n"; });auto D = taskflow.emplace([] () { std::cout << "TaskD\n"; });A.name("A");B.name("B");C.name("C");D.name("D");A.precede(B); // B runs after AA.precede(C); // C runs after AB.precede(D); // D runs after BC.precede(D); // D runs after Cexecutor.run(taskflow).get(); // block until finished// examine the graphtaskflow.dump(std::cout);return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。