News for hackers. Stuff that matters.
Re:The Fastest Mutexes by pizlonator on Wednesday October 02, 2024 @10:07PM (#41726653)
And what, unconditionally futex wakes everyone?

That'll be hella slow

Re:The Fastest Mutexes by wbl on Thursday October 03, 2024 @08:20PM (#41736505)
You did say uncontended!
Re:The Fastest Mutexes by pizlonator on Thursday October 03, 2024 @08:38PM (#41736616)
So you want uncontended unlocks to make a syscall to wake the threads that aren’t there?

That syscall will be worse than a CAS just because it’s a syscall. Not to mention it’ll have to lock some kernel data structure just to figure out that there aren’t any threads to wake.

Re:The Fastest Mutexes by wbl on Friday October 04, 2024 @02:08PM (#41743995)
I think I'm not doing a great job of explaining it.

There are three states of the mutex: locked=1, unlocked=0, and sleeping=2. A thread comes along to a locked mutex, and atomically moves it to sleeping and sleeps via futex. The freeing thread unconditionally writes 0 and atomically sees the old value: if 2 wake all, if 1 no need to wake anybody.

Maybe that is equally expensive to a CAS, but I don't think it ultimately is.

Re:The Fastest Mutexes by pizlonator on Friday October 04, 2024 @03:59PM (#41745048)
“Atomically sees the old value” means you’re doing an atomic RMW, which is more expensive than just a store with a release fence.

Atomic RMW is almost as expensive as CAS. Exactly as expensive as CAS on some cpus.