在 2026-5-21 13:53, Kirill Makurin 写道:
I wrote:

I guess winpthreads' `pthread_spinlock_t` could be a mutex in disguise or 
something like that, in which case first implementation could be more flexible 
in the sense that we can change underlying structure and logic anytime we want. 
I can as well update first implementation to not use loops at all and instead 
use some Windows object for synchronization.

So, here's another implementation for spinlocks. This time, it uses auto-reset 
events; it is mostly original 0004.txt updated to use auto-reset events instead 
of loops. Unlike second version, no other changes to original patch series 
needed. I pushed this version to run through CI[1] and it passes.

Does it make sense to implement a spinlock just as a mutex? like this:

   int
   pthread_spin_init (pthread_spinlock_t *lock, int pshared)
   {
     if (pshared == PTHREAD_PROCESS_SHARED) {
       return ENOSYS;
     }
     return pthread_mutex_init((pthread_mutex_t*)lock, NULL);
   }

   int
   pthread_spin_destroy (pthread_spinlock_t *lock)
   {
     return pthread_mutex_destroy((pthread_mutex_t*)lock);
   }

   int
   pthread_spin_lock (pthread_spinlock_t *lock)
   {
     return pthread_mutex_lock((pthread_mutex_t*)lock);
   }

   int
   pthread_spin_trylock (pthread_spinlock_t *lock)
   {
     return pthread_mutex_trylock((pthread_mutex_t*)lock);
   }

   int
   pthread_spin_unlock (pthread_spinlock_t *lock)
   {
     return pthread_mutex_unlock((pthread_mutex_t*)lock);
   }





--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

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

Reply via email to