For spin-locks that are initialized dynamically, the initial value of the lock
word needs to be propagated to the other processors, before they can attempt to
lock this lock.

The function MemoryBarrier() is part of the Windows API.
<https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-memorybarrier>


2020-07-01  Bruno Haible  <br...@clisp.org>

        windows-spin: Fix race condition on multiprocessor systems.
        * lib/windows-spin.c (glwthread_spin_init): Add a memory barrier.

diff --git a/lib/windows-spin.c b/lib/windows-spin.c
index b90e7ae..4643ac1 100644
--- a/lib/windows-spin.c
+++ b/lib/windows-spin.c
@@ -27,6 +27,7 @@ void
 glwthread_spin_init (glwthread_spinlock_t *lock)
 {
   lock->word = 0;
+  MemoryBarrier ();
 }
 
 int


Reply via email to