News for hackers. Stuff that matters.
Re:Mutexes are faster than Spinlocks by dcolkitt on Saturday January 04, 2020 @12:48PM (#21956222)
> Second, the uncontended case looks like > Parking_lot::Mutex avg 6ms min 4ms max 9ms

This estimate is way too high for the uncontested mutex case. On a modern Linux/Xeon system using GCC, an uncontested mutex lock/unlock is well under 1 microsecond.

I have a lot of experience here from writing low-latency financial systems. The hot path we use is littered with uncontested mutex lock/unlock, and the whole path still runs under 20 microseconds. (With the vast majority of that time unrelated to mutex acquisition.)

The benchmark used in the blog post must be spending the vast majority of its time in some section of code that has nothing to do with lock/unlock.

Re:Mutexes are faster than Spinlocks by gpm on Saturday January 04, 2020 @12:52PM (#21956248)
You're misreading the benchmark, that's 6ms for 10,000 lock/unlocks per thread, 320,000 lock/unlocks total. In other words 0.6 microseconds per thread per lock.
Re:Mutexes are faster than Spinlocks by rwem on Saturday January 04, 2020 @01:07PM (#21956330)
That's still unreasonably high, isn't it? Even a Go sync.Mutex, not exactly a hot-rod implementation, can be acquired and released in < 50ns on the garbage hardware I have before me.
Re:Mutexes are faster than Spinlocks by gpderetta on Saturday January 04, 2020 @03:37PM (#21957309)
On Intel (and probably very similar on AMD) the cost of a completely uncontented, cache hit, simple spin lock acquisition is ~20 clock cycles while the release is almost free.
Re:Mutexes are faster than Spinlocks by atq2119 on Saturday January 04, 2020 @12:49PM (#21956230)
This is the time for whole benchmark run, not for an individual lock/unlock. The article is quite clear on that.
Re:Mutexes are faster than Spinlocks by ncmncm on Saturday January 04, 2020 @09:36PM (#21959255)
As we say in low-latency finance, "a microsecond is an eternity."

If you have threads interacting, whether via mutexes or spinlocks, you have a high-latency system.