在 2026-10-31 13:35, Kirill Makurin via Mingw-w64-public 写道:
On Friday, October 30th, 2026 at 5:48 PM, Luca Bacci <[email protected]> wrote:A few updates on this: We can't really set the event from the the safe part of unlock() (I call "safe" the part of unlock() before the state reset to UNLOCKED). Setting the event early is clearly prone to deadlock! To make things safe we can: 1. Add a count for users in the critical part of unlock() (I call "critical" the part of unlock() after the state reset to UNLOCKED)Can we just have an extra field which would be 0 when there are no threads in the "critical" part of any operation and 1 when there are. Before setting state to `Unlocked`, the thread would `InterlockedIncrement` it; just before returning it would `InterlockedDecrement` it. With this, destroy() could spin until it becomes zero, and only then close the event handle. I think the spin duration should be very brief and should only occur when destroy() is in race with unlock().
This looks like no difference from reference counting. The reference count will only have to be incremented in `pthread_mutex_unlock()` if it wants to use the event, and in `pthread_mutex_destroy()`.
-- Best regards, LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
