]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix TaskResult::clear(). 17329/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Sun, 21 Jul 2024 23:16:48 +0000 (17:16 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 22 Jul 2024 15:38:53 +0000 (09:38 -0600)
include/deal.II/base/task_result.h

index c231e22a15ab16035f213ad7896af0b1835219fd..7ff1fe913518a8acee381aa1a37ea8a8909248f4 100644 (file)
@@ -453,34 +453,21 @@ namespace Threads
   inline void
   TaskResult<T>::clear()
   {
-    // If we have waited before, then return immediately:
+    std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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."));
   }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.