RCU — Read, Copy, Update
RCU coordinates publication and reclamation of shared objects so readers can proceed with low synchronization overhead in suitable workloads. An updater can publish a replacement and arrange to reclaim the old version only after relevant pre-existing read-side critical sections have completed. Readers may observe the replacement while an earlier reader still holds the old object. Reclamation after removal requires an appropriate grace period; readers needing to keep a pointer beyond the protected section must arrange a separate lifetime guarantee. A grace period is not an arbitrary sleep and is not necessarily a period with no readers anywhere. Correct kernel code must use the appropriate RCU flavor, publication and dereference primitives, ordering rules and updater synchronization; RCU does not automatically serialize writers or make arbitrary mutation safe. The example models a reader holding an old immutable version, a new reader observing the replacement and rejection of premature reclamation. It is a sequential teaching model, not an RCU implementation or concurrency test. Example prerequisites: Linux, Bash and Python 3 standard library; run as a non-root user in a private temporary working directory. Example scope: synthetic model. Expected output: modeled old version retained until old reader exits. No system configuration changes.
Formal Syntax & Structure
rcu_read_lock → rcu_dereference → rcu_read_unlock; updater publishes → waits for grace period → reclaimsParameters & Attributes
| Name | Type | Description |
|---|---|---|
| reader | critical section | Lifetime during which a protected reference may be used. |
| publication | update step | Makes replacement available to future readers. |
| grace period | lifetime condition | Waits for relevant pre-existing readers before reclamation. |
Return Value
Conceptual lifecycle; the model prints a reclamation decision rather than invoking kernel RCU APIs.
Working Example
python3 - <<'PY'current='v1'readers={'old-reader':current}retired=currentcurrent='v2'readers['new-reader']=currentcan_reclaim=lambda version: version not in readers.values()assert not can_reclaim(retired)assert readers['new-reader']=='v2'del readers['old-reader']assert can_reclaim(retired) and readers['new-reader']=='v2'print('modeled old version retained until old reader exits')PY