Skip to content

Latest commit

 

History

History
343 lines (246 loc) · 13.9 KB

README.md

File metadata and controls

343 lines (246 loc) · 13.9 KB

NOTE: This repo is mirrored at https://github.com/cryptonector/ctp and https://github.com/nicowilliams/ctp

Q: What is it? A: A user-land-RCU-like API for C, permissively licensed

This repository's only current feature is a read-copy-update (RCU) like, thread-safe variable (TSV) for C. More C thread-primitives may be added in the future, thus the repository's name being quite generic.

A TSV lets readers safely keep using a value read from the TSV until they read the next value. Memory management is automatic: values are automatically destroyed when the last reference to a value is released whether explicitly, or implicitly at the next read, or when a reader thread exits. References can also be relinquished manually. Reads are lock-less and fast, and never block writers. Writers are serialized but otherwise interact with readers without locks, thus writes do not block reads.

In one of the two implementations included readers only execute atomic memory loads and stores, though they loop over that when racing with a writer. As aligned loads and stores are typically atomic on modern archictures, this means no expensive atomic operations are needed -- not even a single atomic increment or decrement.