GitHub Viewer
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include
#include
#include
#include
#include
#include
TEST_CASE("ArenaCorrectness" * doctest::timeout(300)) {
tf::Executor e;
tf::Taskflow taskflow;
std::shared_ptr arena = std::make_shared(e);
thread_local bool is_outer_task_running = false;
try
{
taskflow.for_each_index(0, 32, 1, [&](int i)
{
CHECK(is_outer_task_running == false);
is_outer_task_running = true;
e.isolate(arena, [&] {
// Inside of this functor our worker cannot take tasks that are older than this task (e.g. from the outer for_each_index)
// We can achieve this by switching current thread to another task queue
tf::Taskflow child_taskflow;
child_taskflow.for_each_index(0, 2, 1, [&](int j) {}); // These tasks will be spawned inside of our new TaskQueue of TaskArena "arena"
e.corun(child_taskflow); // Guaranteed to never run tasks from the outer loop
});
is_outer_task_running = false;
});
CHECK(e.run(taskflow).wait_for(std::chrono::seconds(5)) == std::future_status::ready);
}
catch (const std::exception&)
{
std::cout