From 7703cc675f5ce56c1c8b4948e3f040453fd09791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 7 Mar 2018 10:39:28 +0100 Subject: [PATCH] Fix a race-condition in TaskPool. The lock that should surround the foreach loop was given up prematurely. --- source/vibe/core/taskpool.d | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/vibe/core/taskpool.d b/source/vibe/core/taskpool.d index 7e9adee..642cb1f 100644 --- a/source/vibe/core/taskpool.d +++ b/source/vibe/core/taskpool.d @@ -220,9 +220,12 @@ shared final class TaskPool { static assert(areConvertibleTo!(Group!ARGS, Group!FARGS), "Cannot convert arguments '"~ARGS.stringof~"' to function arguments '"~FARGS.stringof~"'."); - foreach (thr; m_state.lock.threads) { - // create one TFI per thread to properly account for elaborate assignment operators/postblit - thr.m_queue.put(callable, args); + { + auto st = m_state.lock; + foreach (thr; st.threads) { + // create one TFI per thread to properly account for elaborate assignment operators/postblit + thr.m_queue.put(callable, args); + } } m_signal.emit(); }