| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -303,11 +303,10 @@ std::shared_future<void> BasicTaskflow<E>::run_until(Framework& f, P&& predicate | |||
| 303 | 303 | ||
| 304 | 304 | // Clear last execution data & Build precedence between nodes and target | |
| 305 | 305 | tpg._bind(f._graph); | |
| 306 | - int num_sinks = tpg._num_sinks; | ||
| 307 | 306 | ||
| 308 | 307 | do { | |
| 309 | 308 | _schedule(tpg._sources); | |
| 310 | - tpg._num_sinks = num_sinks; | ||
| 309 | + tpg._num_sinks = tpg._cached_num_sinks; | ||
| 311 | 310 | } while(!std::invoke(tpg._predicate)); | |
| 312 | 311 | ||
| 313 | 312 | std::invoke(c); | |
@@ -327,11 +326,11 @@ std::shared_future<void> BasicTaskflow<E>::run_until(Framework& f, P&& predicate | |||
| 327 | 326 | tpg._bind(f._graph); | |
| 328 | 327 | } | |
| 329 | 328 | ||
| 330 | - tpg._work = [&f, c=std::forward<C>(c), num_sinks=tpg._num_sinks.load(), this] () mutable { | ||
| 329 | + tpg._work = [&f, c=std::forward<C>(c), this] () mutable { | ||
| 331 | 330 | ||
| 332 | 331 | // case 1: we still need to run the topology again | |
| 333 | 332 | if(!std::invoke(f._topologies.front()->_predicate)) { | |
| 334 | - f._topologies.front()->_num_sinks = num_sinks; | ||
| 333 | + f._topologies.front()->_num_sinks = f._topologies.front()->_cached_num_sinks; | ||
| 335 | 334 | _schedule(f._topologies.front()->_sources); | |
| 336 | 335 | } | |
| 337 | 336 | // case 2: the final run of this topology | |
@@ -348,7 +347,6 @@ std::shared_future<void> BasicTaskflow<E>::run_until(Framework& f, P&& predicate | |||
| 348 | 347 | f._topologies.front()->_promise.set_value(); | |
| 349 | 348 | f._topologies.pop_front(); | |
| 350 | 349 | f._topologies.front()->_bind(f._graph); | |
| 351 | - num_sinks = f._topologies.front()->_num_sinks; | ||
| 352 | 350 | f._mtx.unlock(); | |
| 353 | 351 | _schedule(f._topologies.front()->_sources); | |
| 354 | 352 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,7 @@ class Topology { | |||
| 45 | 45 | ||
| 46 | 46 | PassiveVector<Node*> _sources; | |
| 47 | 47 | std::atomic<int> _num_sinks {0}; | |
| 48 | + int _cached_num_sinks; | ||
| 48 | 49 | ||
| 49 | 50 | std::function<bool()> _predicate {nullptr}; | |
| 50 | 51 | std::function<void()> _work {nullptr}; | |
@@ -126,6 +127,7 @@ inline void Topology::_bind(Graph& g) { | |||
| 126 | 127 | _num_sinks++; | |
| 127 | 128 | } | |
| 128 | 129 | } | |
| 130 | + _cached_num_sinks = _num_sinks; | ||
| 129 | 131 | ||
| 130 | 132 | } | |
| 131 | 133 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -992,6 +992,54 @@ TEST_CASE("Framework" * doctest::timeout(300)) { | |||
| 992 | 992 | REQUIRE(count == 210); | |
| 993 | 993 | } | |
| 994 | 994 | ||
| 995 | + | ||
| 996 | + // Test run_until | ||
| 997 | + for(unsigned W=0; W<=4; ++W) { | ||
| 998 | + | ||
| 999 | + std::atomic<size_t> count {0}; | ||
| 1000 | + tf::Framework f; | ||
| 1001 | + auto A = f.silent_emplace([&](){ count ++; }); | ||
| 1002 | + auto B = f.silent_emplace([&](auto& subflow){ | ||
| 1003 | + count ++; | ||
| 1004 | + auto B1 = subflow.silent_emplace([&](){ count++; }); | ||
| 1005 | + auto B2 = subflow.silent_emplace([&](){ count++; }); | ||
| 1006 | + auto B3 = subflow.silent_emplace([&](){ count++; }); | ||
| 1007 | + B1.precede(B3); B2.precede(B3); | ||
| 1008 | + }); | ||
| 1009 | + auto C = f.silent_emplace([&](){ count ++; }); | ||
| 1010 | + auto D = f.silent_emplace([&](){ count ++; }); | ||
| 1011 | + | ||
| 1012 | + A.precede(B, C); | ||
| 1013 | + B.precede(D); | ||
| 1014 | + C.precede(D); | ||
| 1015 | + | ||
| 1016 | + tf::Taskflow tf(W); | ||
| 1017 | + tf.run_until(f, [run=10]() mutable { return run-- == 0; }, | ||
| 1018 | + [&](){ | ||
| 1019 | + REQUIRE(count == 70); | ||
| 1020 | + count = 0; | ||
| 1021 | + } | ||
| 1022 | + ).get(); | ||
| 1023 | + | ||
| 1024 | + | ||
| 1025 | + tf.run_until(f, [run=10]() mutable { return run-- == 0; }, | ||
| 1026 | + [&](){ | ||
| 1027 | + REQUIRE(count == 70); | ||
| 1028 | + count = 0; | ||
| 1029 | + auto E = f.silent_emplace([&](){ count ++; }); | ||
| 1030 | + auto F = f.silent_emplace([&](){ count ++; }); | ||
| 1031 | + A.precede(E).precede(F); | ||
| 1032 | + }); | ||
| 1033 | + | ||
| 1034 | + tf.run_until(f, [run=10]() mutable { return run-- == 0; }, | ||
| 1035 | + [&](){ | ||
| 1036 | + REQUIRE(count == 90); | ||
| 1037 | + count = 0; | ||
| 1038 | + } | ||
| 1039 | + ).get(); | ||
| 1040 | + | ||
| 1041 | + } | ||
| 1042 | + | ||
| 995 | 1043 | } | |
| 996 | 1044 | ||
| 997 | 1045 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments