3 ms·
Right, but spinlocks have no concept of fairness at all. With a mutex on thread might experience unfairness for a few ms, a spinlock has no bound.
by zamalek 4y ago
Right, but spinlocks have no concept of fairness at all. With a mutex on thread might experience unfairness for a few ms, a spinlock has no bound.
- jimmyed 4y agoIt's not mutexes that are fair, it's the scheduling that is fair. Scheduling tries to prevent starvation and schedules the preempted mutex thread at least periodically.
- zamalek 4y agoThat's unnecessary pedantry, in context. I am explaining an important con of spinlocks. Whether it is because mutexes are fair or because they behave fair is completely irrelevant. The point is that if you use spinlocks (which the article incorrectly calls mutexes), then you could see unintuitive behavior under load.
- gpderetta 4y agoYou can have fair spinlocks if you handle queuing yourself. Also the article does indeed implement a real mutex (although a buggy one), not a spinlock. std::atomic::wait will use futexes (or whatever) underneath to genuinely put the process to sleep until it receives a wakeup.