[Openmp-commits] [PATCH] D80480: [OpenMP] Fix a race in task queue reallocation

Joachim Protze via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Sun May 24 14:24:07 PDT 2020


protze.joachim updated this revision to Diff 265941.
protze.joachim added a comment.

Addressed Andrey's comment.

I was thinking about a test. The problem I see is that this only manifests under rare circumstances or in complex code.
The best I could think of is adding additional assertions: (head + ntasks) & (size-1) == tail


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80480/new/

https://reviews.llvm.org/D80480

Files:
  openmp/runtime/src/kmp_tasking.cpp


Index: openmp/runtime/src/kmp_tasking.cpp
===================================================================
--- openmp/runtime/src/kmp_tasking.cpp
+++ openmp/runtime/src/kmp_tasking.cpp
@@ -298,6 +298,7 @@
 static void __kmp_realloc_task_deque(kmp_info_t *thread,
                                      kmp_thread_data_t *thread_data) {
   kmp_int32 size = TASK_DEQUE_SIZE(thread_data->td);
+  KMP_DEBUG_ASSERT(TCR_4(thread_data->td.td_deque_ntasks) == size);
   kmp_int32 new_size = 2 * size;
 
   KE_TRACE(10, ("__kmp_realloc_task_deque: T#%d reallocating deque[from %d to "
@@ -381,8 +382,11 @@
     } else {
       __kmp_acquire_bootstrap_lock(&thread_data->td.td_deque_lock);
       locked = 1;
-      // expand deque to push the task which is not allowed to execute
-      __kmp_realloc_task_deque(thread, thread_data);
+      if (TCR_4(thread_data->td.td_deque_ntasks) >=
+          TASK_DEQUE_SIZE(thread_data->td)) {
+        // expand deque to push the task which is not allowed to execute
+        __kmp_realloc_task_deque(thread, thread_data);
+      }
     }
   }
   // Lock the deque for the task push operation
@@ -3659,7 +3663,11 @@
       return result;
 
     __kmp_acquire_bootstrap_lock(&thread_data->td.td_deque_lock);
-    __kmp_realloc_task_deque(thread, thread_data);
+    if (TCR_4(thread_data->td.td_deque_ntasks) >=
+        TASK_DEQUE_SIZE(thread_data->td)) {
+      // expand deque to push the task which is not allowed to execute
+      __kmp_realloc_task_deque(thread, thread_data);
+    }
 
   } else {
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80480.265941.patch
Type: text/x-patch
Size: 1538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200524/b8182c44/attachment-0001.bin>


More information about the Openmp-commits mailing list