1.源码实现
#include <taskflow/taskflow.hpp>
int main()
{
tf::Taskflow taskflow;
auto [A, B, C, D] = taskflow.emplace(
[](){ std::cout << "TaskA\n"; },
[](){ std::cout << "TaskB\n"; },
[](){ std::cout << "TaskC\n"; },
[](){ std::cout << "TaskD\n"; }
);
A.precede(B, C);
B.precede(D);
C.precede(D);
taskflow.wait_for_all();
return 0;
}
2.编译源码
$ g++ -o test test.cpp -std=c++17 -lpthreadyunx
3.运行及其结果
$ ./test
TaskA
TaskC
TaskB
TaskD
网友评论