|
|
|
|
|
by comex
2377 days ago
|
|
> On the other hand, I have yet to learn whether Mac OS has any synchronisation primitives that mitigate mutex priority inversion. It does! xnu supports priority inheritance through "turnstiles", a kernel-internal mechanism which is used by default by a number of locking primitives (list at [1]), including normal pthread mutexes (though not read-write locks [2]), as well as the os_unfair_lock API (via the ulock syscalls). With pthread mutexes, you can actually explicitly request priority inheritance by calling pthread_mutexattr_setprotocol [3] with PTHREAD_PRIO_INHERIT; the Apple implementation supports it, but currently ignores the protocol setting and just gives all mutexes priority inheritance. [1] https://opensource.apple.com/source/xnu/xnu-4903.241.1/osfmk... [2] https://opensource.apple.com/source/libpthread/libpthread-33..., search for _kwq_use_turnstile [2] https://linux.die.net/man/3/pthread_mutexattr_setprotocol |
|
Do you have any information on how long this "turnstiles" feature has been available? [1] I was aware that the userspace pthread libraries implement but ignore PTHREAD_PRIO_INHERIT, but wasn't aware that the underlying implementation gave priority inheritance semantics.
Update: Looks like the "turnstiles" feature may have its origins in Solaris. [2]
[1] This link would suggest as of Mac OS 10.14: http://newosxbook.com/articles/12-10.14.html
[2] http://sunsite.uakom.sk/sunworldonline/swol-08-1999/swol-08-...