On Wed Jul 10 17:36:44 2024 +0000, Paul Gofman wrote:
Doesn't glibc's pthread mutex implementation use futexes already? My quick look at nptl/pthread_mutex_lock.c suggests that it does, at least for some cases. Ideally, that is a better place for that than Wine apart from maybe some specific places, like, e. g., implementing Windows sync primitives. There are a lot of things to consider for general implementation to be used as drop in replacement. And, as a secondary note, a synthetic test measuring sync primitive lock and unlock time in a tight loop is probably not all that convincing, proper justification of the universal benefits is more complicated than that.
@gofman Thanks for the tip on the glibc sources. I haven’t looked there for a long time since I wrote my crt0 on nasm. For me this is more of an academic interest, theoretically we can reduce the number of expensive context switches in the scheduler. As for Windows sync primitives, this work has already been done by ZF and I don’t understand the Wine code so well yet. Yes, you are right about synthetic tests, because when locking, the lock queue of threads can also be important. And if I'm not mistaken, FUTEX_WAIT and FUTEX_WAKE take into account the queue.