From a2580fb1919ac6d272fa6f9bcae9e269f0403e3a Mon Sep 17 00:00:00 2001 From: Chris Cotter Date: Mon, 6 Jan 2025 12:20:21 -0500 Subject: [PATCH] Use async_manual_reset_event instead of timer The benchmark hangs when run with 1 million tasks. I haven't looked into it, but perhaps there is an inefficient implementation of the timer in unifex. As a POC, I reimplemented the unifex benchmark to spawn N tasks and have them wait until all N are created before completing the program. I did not change the other benchmarks. --- unifex_bench/main.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/unifex_bench/main.cpp b/unifex_bench/main.cpp index f627ec1..593abf1 100644 --- a/unifex_bench/main.cpp +++ b/unifex_bench/main.cpp @@ -1,33 +1,40 @@ #include #include -#include +#include +#include +#include #include +#include +#include #include #include +#include #include #include #include -unifex::timed_single_thread_context TIMER; - -auto async_sleep(auto s) { return unifex::schedule_after(TIMER.get_scheduler(), s); } - int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, - "Please specify the number of tasks\n" - "example: %s 10000\n", - argv[0]); + "Please specify the number of tasks\n" + "example: %s 10000\n", + argv[0]); return EXIT_FAILURE; } std::vector> tasks; + unifex::async_manual_reset_event evt; + int counter = 0; for (auto i : std::views::iota(0, std::stoi(argv[1]))) { tasks.push_back( - []() -> unifex::task { co_await async_sleep(std::chrono::seconds(10)); }()); + [](int& counter, auto& evt) -> unifex::task { ++counter; co_await evt.async_wait(); --counter; }(counter, evt)); } - - unifex::sync_wait(unifex::when_all_range(std::move(tasks))); -} \ No newline at end of file + + unifex::sync_wait(unifex::when_all( + unifex::when_all_range(std::move(tasks)), + unifex::just() | unifex::then([&] { std::cout << "counter=" << counter << "\n"; evt.set(); }) + )); + return 0; +}