News for hackers. Stuff that matters.
Re:The Fastest Mutexes by spacechild1 on Thursday October 03, 2024 @12:29AM (#41727389)
> If you want your spinlock to be hella fast on contention just make sure you `sched_yield` before each retry

Shouldn't you rather use pause instructions (_mm_pause, __yield, ISB, etc.) instead of thread switching? That's what I have seen in most spin lock implementations. Maybe it depends on the use case?

Re:The Fastest Mutexes by xxs on Thursday October 03, 2024 @03:07AM (#41728018)
start with few attempts w/o pause, just busy CAS, then CAS + pause, then yield (and backoff/sleep with random duration)
Re:The Fastest Mutexes by senderista on Thursday October 03, 2024 @02:25PM (#41733410)
No, you shouldn’t be calling CAS in a tight loop, but rather a relaxed load to check if a CAS might be successful, with PAUSE equivalent after each load. After spinning for ~context switch latency you should back off with sched_yield before retrying the spin loop (and eventually start sleeping on backoff with exponential jitter etc).
Re:The Fastest Mutexes by xxs on Thursday October 03, 2024 @02:35PM (#41733519)
of course, there is very rarely any a naked CAS