LIU Hao wrote:

>在 2026-5-14 23:15, Kirill Makurin 写道:
>> Do you think we can improve the while loop in `pthread_spin_lock` or we can 
>> keep it as-is? I believe you and other people on the list are more familiar 
>> with this kind of stuff than I am. My primary goal is to provide 
>> POSIX-conformant implementation.
>
> There's a report saying that it takes significant time:
> https://github.com/msys2/MINGW-packages/issues/29108#issuecomment-4384999469

And on top of that, winpthreads' spinlocks are also broken.

> So maybe it's worth doing. However, as said earlier, I think this is not a 
> very good implementation. A
> user-mode thread should not spin dead; it needs to be nice (!) to the 
> scheduler.

I honestly can't imagine situation when I would consider using a spinlock 
instead of mutex or rwlock.

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.

Another thing that may be interesting. I ran the following in my Msys2 shell:

```
$ (for exe in /ucrt64/bin/*.exe; do if nm $exe 2>/dev/null | grep -q 
pthread_spin; then echo $exe; fi done)
/ucrt64/bin/addr2line-drmingw.exe
/ucrt64/bin/catchsegv.exe
/ucrt64/bin/drmingw.exe

$ (for exe in /ucrt64/bin/*.dll; do if nm $exe 2>/dev/null | grep -q 
pthread_spin; then echo $exe; fi done)
/ucrt64/bin/exchndl.dll
/ucrt64/bin/mgwhelp.dll
```

It seems like not many packages use spinlocks in general. If you replace 
`ptrehad_spin` with just `pthread_` and do not silence grep, you'll see that 
most images use mutexes, pthread_once and pthread_{get,set}specific.

- Kirill Makurin

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

Reply via email to