diff --git a/FWCore/Concurrency/interface/include_first_syncWait.h b/FWCore/Concurrency/interface/include_first_syncWait.h index 218a1958f80c3..452637d4fc360 100644 --- a/FWCore/Concurrency/interface/include_first_syncWait.h +++ b/FWCore/Concurrency/interface/include_first_syncWait.h @@ -8,32 +8,19 @@ // Created by Chris Jones on 2/24/21. // #include "FWCore/Concurrency/interface/WaitingTaskHolder.h" +#include "FWCore/Concurrency/interface/FinalWaitingTask.h" #include "oneapi/tbb/task_group.h" -#include "oneapi/tbb/task.h" #include namespace edm { template [[nodiscard]] std::exception_ptr syncWait(F&& iFunc) { std::exception_ptr exceptPtr{}; - //oneapi::tbb::task::suspend can only be run from within a task running in this arena. For 1 thread, - // it is often (always?) the case where not such task is being run here. Therefore we need - // to use a temp task_group to start up such a task. oneapi::tbb::task_group group; - group.run([&]() { - oneapi::tbb::task::suspend([&](oneapi::tbb::task::suspend_point tag) { - auto waitTask = make_waiting_task([tag, &exceptPtr](std::exception_ptr const* iExcept) { - if (iExcept) { - exceptPtr = *iExcept; - } - oneapi::tbb::task::resume(tag); - }); - iFunc(WaitingTaskHolder(group, waitTask)); - }); //suspend - }); //group.run + FinalWaitingTask last{group}; + group.run([&]() { iFunc(WaitingTaskHolder(group, &last)); }); //group.run - group.wait(); - return exceptPtr; + return last.waitNoThrow(); } } // namespace edm #endif /* FWCore_Concurrency_syncWait_h */ diff --git a/FWCore/Concurrency/src/SerialTaskQueue.cc b/FWCore/Concurrency/src/SerialTaskQueue.cc index edcc6ef68a069..1e2435764a148 100644 --- a/FWCore/Concurrency/src/SerialTaskQueue.cc +++ b/FWCore/Concurrency/src/SerialTaskQueue.cc @@ -12,7 +12,7 @@ // // system include files -#include "oneapi/tbb/task.h" +#include "oneapi/tbb/task_group.h" // user include files #include "FWCore/Concurrency/interface/SerialTaskQueue.h" @@ -30,11 +30,8 @@ SerialTaskQueue::~SerialTaskQueue() { bool isTaskChosen = m_taskChosen; if ((not isEmpty and not isPaused()) or isTaskChosen) { oneapi::tbb::task_group g; - g.run([&g, this]() { - oneapi::tbb::task::suspend([&g, this](oneapi::tbb::task::suspend_point tag) { - push(g, [tag]() { oneapi::tbb::task::resume(tag); }); - }); //suspend - }); //group run + tbb::task_handle last{g.defer([]() {})}; + push(g, [&g, &last]() { g.run(std::move(last)); }); g.wait(); } }