From 8eea55b51c4d9be16c1b99a7c8806fb7fc195cdb Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 10 Feb 2018 23:39:30 -0500 Subject: [PATCH] Simplifies `perform_parallel` slightly. --- .../Implementation/MultiCRTMachine.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiCRTMachine.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiCRTMachine.cpp index a18c39c13..d7f33104d 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiCRTMachine.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiCRTMachine.cpp @@ -24,25 +24,25 @@ void MultiCRTMachine::perform_parallel(const std::function machines_lock(machines_mutex_); + std::lock_guard lock(mutex); outstanding_machines = machines_.size(); for(std::size_t index = 0; index < machines_.size(); ++index) { - queues_[index].enqueue([&mutex, &condition, this, index, function, &outstanding_machines]() { - CRTMachine::Machine *crt_machine = machines_[index]->crt_machine(); + CRTMachine::Machine *crt_machine = machines_[index]->crt_machine(); + queues_[index].enqueue([&mutex, &condition, crt_machine, function, &outstanding_machines]() { if(crt_machine) function(crt_machine); - std::unique_lock lock(mutex); - outstanding_machines--; + { + std::lock_guard lock(mutex); + outstanding_machines--; + } condition.notify_all(); }); } } - while(true) { - std::unique_lock lock(mutex); - condition.wait(lock); - if(!outstanding_machines) break; - } + std::unique_lock lock(mutex); + condition.wait(lock, [&outstanding_machines] { return !outstanding_machines; }); } void MultiCRTMachine::perform_serial(const std::function &function) {