On Thursday 23 October 2025 11:02:28 LIU Hao wrote:
> 在 2025-10-23 02:40, Pali Rohár 写道:
> > Thank you very much for information. So from this information it looks
> > like that the volatile keyword is not required on more places in
> > mingw-w64-libraries/winpthreads/src/spinlock.c file.
> > 
> > Would you have a time to revisit that file?
> 
> There are 6 occurrences of `volatile` in spinlock.c, and they are all parts
> of pointee types, so I believe all of them are unnecessary.

Ok, what about this change?

winpthreads: Remove unnecessary volatile from spinlock.c

diff --git a/mingw-w64-libraries/winpthreads/src/spinlock.c 
b/mingw-w64-libraries/winpthreads/src/spinlock.c
index 0590e0f4f982..452c36528a6b 100644
--- a/mingw-w64-libraries/winpthreads/src/spinlock.c
+++ b/mingw-w64-libraries/winpthreads/src/spinlock.c
@@ -57,8 +57,8 @@ pthread_spin_destroy (pthread_spinlock_t *lock)
 int
 pthread_spin_lock (pthread_spinlock_t *lock)
 {
-  volatile spinlock_word_t *lk = (volatile spinlock_word_t *)lock;
-  while (unlikely(InterlockedExchangePointer((PVOID volatile *)lk, 0) == 0))
+  spinlock_word_t *lk = (spinlock_word_t *)lock;
+  while (unlikely(InterlockedExchangePointer((PVOID*)lk, 0) == 0))
     YieldProcessor();
   return 0;
 }
@@ -67,18 +67,18 @@ int
 pthread_spin_trylock (pthread_spinlock_t *lock)
 {
   spinlock_word_t *lk = (spinlock_word_t *)lock;
-  return InterlockedExchangePointer((PVOID volatile *)lk, 0) == 0 ? EBUSY : 0;
+  return InterlockedExchangePointer((PVOID*)lk, 0) == 0 ? EBUSY : 0;
 }


 int
 pthread_spin_unlock (pthread_spinlock_t *lock)
 {
-  volatile spinlock_word_t *lk = (volatile spinlock_word_t *)lock;
+  spinlock_word_t *lk = (spinlock_word_t *)lock;
 #if defined(__GNUC__) || defined(__clang__)
   __atomic_store_n(lk, -1, __ATOMIC_RELEASE);
 #else
-  InterlockedExchangePointer((PVOID volatile *)lk, (void*)-1);
+  InterlockedExchangePointer((PVOID*)lk, (void*)-1);
 #endif
   return 0;
 }


> There are some uses in other files, as parts of definitions of fields or
> variables, like in mutex.c and in thread.c. Those fields should be read with
> atomic operations, but at the moment they aren't, so `volatile` isn't safe
> to remove there for now. (I don't know how to do `__atomic_load_n` in MSVC.)
> 
> 
> -- 
> Best regards,
> LIU Hao


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to