News for hackers. Stuff that matters.
Re:Correctly implementing a spinlock in Modern C++ by AnanasAttack on Friday June 25, 2021 @08:53PM (#27638015)
Correctly using a spinlock: Never when preemption is enabled
Re:Correctly implementing a spinlock in Modern C++ by notacoward on Friday June 25, 2021 @09:07PM (#27638086)
Therefore, also never when hold times and/or contention are non-trivial (i.e. obviating the PAUSE addition).
Re:Correctly implementing a spinlock in Modern C++ by namibj on Friday June 25, 2021 @10:08PM (#27638416)
That one isn't actually as strict. Just because you used a spinlock doesn't mean you cause pathological degradation.

spinlocks in systems with preemption are only allowed if the scheduler knows about them, though. Otherwise a throughput-optimizing scheduler may cause hold times in the range of seconds, by keeping an aquiring thead active with the holding thread asleep. Such a scheduler wouldn't be suitable for interactive workloads, but for non-networked batch tasks it should be quite efficient (due to a combination of calling the scheduling logic less often (thus wasting less time on it), and less cache contention with the application.

In interrupt handlers and such you may need to use spin locks, as you can't sleep either way. The rule about preemption still applies though, and aside from fairness issues, will take care of preventing pathological hold times.

Re:Correctly implementing a spinlock in Modern C++ by rigtorp on Tuesday June 29, 2021 @03:49PM (#27680855)
Yes that's right!