Skip to content

Read-copy-update

Category: Lock-free · Status: stub

One line: Readers use shared data without any lock while a writer publishes a modified copy, and the old version is freed only after every reader that might still see it has finished.

Also called: RCU, copy-on-write.

How it connects

flowchart LR
  n_atomic_variable["Atomic variable"]
  n_rcu["Read-copy-update"]
  n_read_write_lock["Read-write lock"]
  n_rcu ---|or| n_read_write_lock
  n_rcu -->|uses| n_atomic_variable
  classDef center stroke-width:3px
  class n_rcu center
  classDef outside stroke-dasharray: 4 3
  class n_atomic_variable,n_read_write_lock outside

In each language

Go The atomic.Value docs keep a frequently read, rarely updated map with a copy-on-write idiom
C++ <rcu> (C++26): rcu_obj_base, rcu_domain, rcu_synchronize and rcu_retire
Java CopyOnWriteArrayList makes a fresh copy of the underlying array for every mutation
The operating system Linux kernel RCU ↗, optimized for read-mostly data: an update frees the old version after a grace period

Where to read more