[PATCH v2] Cygwin: pthread: Fix a race issue introduced by the commit 2c5433e5da82

Noel Grandin noelgrandin@gmail.com
Thu May 30 08:59:59 GMT 2024



On 5/30/2024 10:47 AM, Bruno Haible wrote:
> 
> SRW locks are spin-locks. Since they are only pointer-sized,
> ReleaseSRWLockExclusive cannot notify other threads — unlike CRITICAL_SECTION.
> Therefore, AcquireSRWLockExclusive must busy-loop when the lock is already
> held.
> 

No, they only spin briefly, before calling into the OS to sleep - see the article about their internals here:

https://learn.microsoft.com/en-us/archive/msdn-magazine/2012/november/windows-with-c-the-evolution-of-synchronization-in-windows-and-c#slim-readerwriter-lock


Alternatively, Windows already has an API for init-once i.e.
   https://learn.microsoft.com/en-us/windows/win32/sync/one-time-initialization


More information about the Cygwin mailing list