在 2026-5-11 21:12, Kirill Makurin 写道:
Hello,

In winpthreads, since we integrated test suite with Automake, we have a few 
tests marked as XFAIL:

- Some mutex tests
- Two spinlock tests (spin1.c and spin3.c)

The first two attached patches address issues with mutex tests; more details 
are in commit messages.

Current spinlock implementation in winpthreads does not keep track of lock 
ownership. It has an effect that thread A can unlock lock held by thread B; 
this behavior does not conform to POSIX specification and causes spin3.c to 
fail.
I think this spinlock implementation is over-complicated. Since `pthread_spinlock_t` is just an integer, you can store the ID of the owner thread in there.


And old code has

   while (unlikely(InterlockedExchangePointer((PVOID*)lk, 0) == 0))
     YieldProcessor();

which effects a huge amount of cache pressure. This can be much better:

   while (unlikely(InterlockedExchangePointer((PVOID*)lk, 0) == 0))
     for (int i = 0; i != 100; ++i)
       YieldProcessor();

The magic number 100 is, of course, an arbitrary choice. I believe you can find a better one basing on benchmark results on your hardware.



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