bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

windows-spin: Fix race condition on multiprocessor systems


From: Bruno Haible
Subject: windows-spin: Fix race condition on multiprocessor systems
Date: Wed, 01 Jul 2020 22:58:33 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; )

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  <bruno@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

[Prev in Thread] Current Thread [Next in Thread]