xtc_rcu(3)

---

xtc_rcu(3)

epoch-based read-copy-update

XTC_RCU(3) Library Functions Manual XTC_RCU(3)

xtc_rcu_init, xtc_rcu_fini, xtc_rcu_read_lock, xtc_rcu_read_unlock, xtc_rcu_retire, xtc_rcu_synchronize, xtc_rcu_current_epochepoch-based read-copy-update

#include <xtc.h>
#include <xtc_rcu.h>

int
xtc_rcu_init(void);

void
xtc_rcu_fini(void);

void
xtc_rcu_read_lock(void);

void
xtc_rcu_read_unlock(void);

void
xtc_rcu_retire(void *p, xtc_rcu_free_fn fn);

void
xtc_rcu_synchronize(void);

uint64_t
xtc_rcu_current_epoch(void);

xtc_rcu is an epoch-based read-copy-update primitive for read-mostly data structures with deferred reclamation. Readers operate inside critical sections delimited by () and (). Writers atomically swap pointers to new state and call () to free the old state once all readers that may have observed it have exited their critical sections.

() blocks until all currently-active readers have exited. Used by writers that want to free old state synchronously rather than via the deferred-retire path.

The implementation tracks per-thread epoch counters in a TLS-registered linked list. Retired records bucket by epoch; records two epochs old are guaranteed safe to free.

() returns the current value of the global epoch counter. It is intended for diagnostics and tests -- the counter advances on each grace period.

Both give wait-free reads. Trade-offs:

xtc_rcu
Pointer-swap; arbitrary structure shape; deferred reclamation. Best when the structure is small or rare-write.
xtc_lrlock
Two-copy + replay; suits structures where the data is updated in place (buffer pools, page caches). Memory is 2x; reclamation is immediate via the publish-drain.

xtc_lrlock(3), xtc_lwlock(3), xtc(7)

Appeared in xtc 0.1.

May 28, 2026 Debian

View the mdoc source