From 6593cf0946754c424fc5654cc05cb1e3a916d0d3 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sun, 21 Jul 2024 17:16:48 -0600 Subject: [PATCH] Fix TaskResult::clear(). --- include/deal.II/base/task_result.h | 37 ++++++++++-------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/include/deal.II/base/task_result.h b/include/deal.II/base/task_result.h index c231e22a15..7ff1fe9135 100644 --- a/include/deal.II/base/task_result.h +++ b/include/deal.II/base/task_result.h @@ -453,34 +453,21 @@ namespace Threads inline void TaskResult::clear() { - // If we have waited before, then return immediately: + std::lock_guard lock(mutex); + if (result_is_available) - return; - else - // If we have not waited, wait now. We need to use the double-checking - // pattern to ensure that if two threads get to this place at the same - // time, one returns right away while the other does the work. Note - // that this happens under the lock, so only one thread gets to be in - // this code block at the same time: { - std::lock_guard lock(mutex); - - if (result_is_available) - return; - else - Assert(task.has_value() == false, - ExcMessage("You cannot destroy a TaskResult object " - "while it is still waiting for its associated task " - "to finish. See the documentation of this class' " - "destructor for more information.")); + // First make clear that the result is no longer available, then + // reset the object: + result_is_available = false; + task_result.reset(); } - std::lock_guard lock(mutex); - // First make clear that the result is no longer available: - result_is_available = false; - // Then abandon a previous task, should there have been one. Also abandon - // any previously available returned object - task.reset(); - task_result.reset(); + else + Assert(task.has_value() == false, + ExcMessage("You cannot destroy a TaskResult object " + "while it is still waiting for its associated task " + "to finish. See the documentation of this class' " + "destructor for more information.")); } -- 2.39.5