[Openmp-commits] [openmp] 236ac68 - [OpenMP] Add memory barrier to solve data race

Bryan Chan via Openmp-commits openmp-commits at lists.llvm.org
Fri Mar 27 13:32:55 PDT 2020


Author: Henry Kao
Date: 2020-03-27T16:32:28-04:00
New Revision: 236ac68fa5b173e54b181e0a03216dfd8fd4f95e

URL: https://github.com/llvm/llvm-project/commit/236ac68fa5b173e54b181e0a03216dfd8fd4f95e
DIFF: https://github.com/llvm/llvm-project/commit/236ac68fa5b173e54b181e0a03216dfd8fd4f95e.diff

LOG: [OpenMP] Add memory barrier to solve data race

Data race occurs when acquiring lock for critical section
triggering assertion failure. Added barrier to ensure
all memory is commited before checking assertion.

Reviewed By: Hahnfeld

Differential Revision: https://reviews.llvm.org/D76780

Added: 
    

Modified: 
    openmp/runtime/src/kmp_lock.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/kmp_lock.cpp b/openmp/runtime/src/kmp_lock.cpp
index 2cc9e08278c4..8e20c6c2c8ee 100644
--- a/openmp/runtime/src/kmp_lock.cpp
+++ b/openmp/runtime/src/kmp_lock.cpp
@@ -1239,6 +1239,9 @@ __kmp_acquire_queuing_lock_timed_template(kmp_queuing_lock_t *lck,
       KMP_MB();
       // ToDo: Use __kmp_wait_sleep or similar when blocktime != inf
       KMP_WAIT(spin_here_p, FALSE, KMP_EQ, lck);
+      // Synchronize writes to both runtime thread structures
+      // and writes in user code.
+      KMP_MB();
 
 #ifdef DEBUG_QUEUING_LOCKS
       TRACE_LOCK(gtid + 1, "acq spin");


        


More information about the Openmp-commits mailing list