From ba62c665aa2d99db3e5a3cd7c1622996475bb559 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 9 Nov 2022 12:18:21 +0100 Subject: [PATCH] WorkQueue#ParallelFor(): allocate lambda once per thread, not once per item --- lib/base/workqueue.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/base/workqueue.hpp b/lib/base/workqueue.hpp index 9c8a6b8f9..2cfec6471 100644 --- a/lib/base/workqueue.hpp +++ b/lib/base/workqueue.hpp @@ -89,10 +89,13 @@ public: count++; EnqueueUnlocked(lock, [&items, func, offset, count, this]() { - for (SizeType j = offset; j < offset + count; j++) { - RunTaskFunction([&func, &items, j]() { - func(items[j]); - }); + SizeType j; + TaskFunction f = [&func, &items, &j]() { + func(items[j]); + }; + + for (j = offset; j < offset + count; j++) { + RunTaskFunction(f); } });