Readers pay nothing
Read copy update, or RCU, is built for data that is read constantly but updated rarely. Readers take no lock and write nothing shared. They simply follow the current pointer, which makes reads essentially free. The complexity all lives on the writer side.
The update dance
A writer never edits data in place while readers may see it. Instead it:
- Copies the structure or node it wants to change
- Applies the modification to the private copy
- Publishes the new version with a single atomic pointer swap
After the swap, new readers see the new version while in flight readers keep using the old one.
Reclaiming safely
The old version cannot be freed immediately because readers may still hold it. RCU waits for a grace period, the point after which every reader that could have seen the old version has finished. Readers mark their critical sections, and once all pre existing readers have passed through a quiescent state, the old copy is reclaimed.
Key idea
RCU gives readers lock free zero overhead access by having writers publish copies atomically and reclaim old versions only after a grace period.