From c60db6f71c8e8a8b5ff1b4d50ca278e026917d7c Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Fri, 13 Jan 2023 14:18:09 +0100
Subject: [PATCH] ISimulation::runSingleSimulation: all-in-one thread works

---
 Sim/Simulation/ISimulation.cpp | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/Sim/Simulation/ISimulation.cpp b/Sim/Simulation/ISimulation.cpp
index e8752aeefa7..30033397468 100644
--- a/Sim/Simulation/ISimulation.cpp
+++ b/Sim/Simulation/ISimulation.cpp
@@ -25,8 +25,8 @@
 #include "Sim/Computation/IComputation.h"
 #include <gsl/gsl_errno.h>
 #include <iostream>
-#include <thread>
 #include <mutex>
+#include <thread>
 
 namespace {
 
@@ -233,16 +233,17 @@ void ISimulation::runSingleSimulation(const ReSample& re_sample, size_t batch_st
             const size_t thread_size = batchSize(n_threads, i_thread, batch_size);
             if (thread_size == 0)
                 break;
-            threads.emplace_back(new std::thread([&]() {
-                mutex.lock();
-                const auto& c = createComputation(re_sample, thread_start, thread_size);
-                mutex.unlock();
-                c->compute(); // <---- here most work is done (threaded case)!
-                mutex.lock();
-                if (!c->isCompleted())
-                    failure_messages.push_back(c->errorMessage());
-                mutex.unlock();
-            }));
+            threads.emplace_back(new std::thread(
+                [this, &re_sample, &failure_messages, &mutex, thread_start, thread_size]() {
+                    mutex.lock();
+                    const auto& c = createComputation(re_sample, thread_start, thread_size);
+                    mutex.unlock();
+                    c->compute(); // <---- here most work is done (threaded case)!
+                    mutex.lock();
+                    if (!c->isCompleted())
+                        failure_messages.push_back(c->errorMessage());
+                    mutex.unlock();
+                }));
         }
 
         // Wait for threads to complete.
-- 
GitLab