Lock-free programming with per-CPU and RCU
As you have learned, when operating upon shared writable data, the critical section must be protected in some manner. Locking is perhaps the most common technology used to effect this protection. It’s not all rosy, though, as performance can suffer.
To quite intuitively see why, consider a few physical-world analogies to a lock:
- One is a funnel, with the stem of the funnel – the ‘“critical section” – just wide enough to allow one thread at a time to flow through, and no more.
- Another is a single toll booth on a wide and busy highway, or a set of traffic lights at a busy intersection.
These analogies help us visualize and understand why locking can cause bottlenecks, slowing performance down to a crawl in some drastic cases. Worse, these adverse effects can be multiplied on high-end (SMP/NUMA) multicore systems (with a few hundred cores); in effect, locking doesn’...