Re:The Fastest Mutexes
by PaulDavisThe1st on Thursday October 03, 2024 @08:04PM
(#41736414)
Excellent reminder. Yes, this is both a design defect of try/unlock that can't really be solved, and an implementation defect on several platforms that makes it worse than it actually needs to be (Windows, I'm looking at you)
[ Parent
| on HN ]
Re:The Fastest Mutexes
by spacechild1 on Friday October 04, 2024 @09:44AM
(#41741323)
One thing I've been using is a spinlock where the RT thread only uses try_lock() + fallback path and the NRT thread(s) call try_lock() in a loop with pause instructions and occasional thread yielding (or even sleeping). This might waste lots of CPU cycles when a NRT thread tries to acquire a lock that is already held by the RT thread, but assuming this only happens occasionally/rarely, it's a reasonable trade-off.