From: Wolfgang Bangerth Date: Sun, 21 Jul 2024 23:16:48 +0000 (-0600) Subject: Fix TaskResult::clear(). X-Git-Tag: v9.6.0-rc1~27^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6593cf0946754c424fc5654cc05cb1e3a916d0d3;p=dealii.git Fix TaskResult::clear(). --- 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.")); }