Module rcu

RCU-synchronized hash table.

Provides a concurrent hash table using Read-Copy-Update (RCU) synchronization. Reads are lockless; writes are serialized. Keys are strings, values can be booleans, integers, lunatik objects, or nil (to delete an entry).

See examples/shared.lua for a practical example.

Class rcu_table

rcu_table:__index (key) Retrieves a value from the table (RCU-protected, lockless).
rcu_table:__newindex (key, value) Sets or removes a value in the table (serialized).
rcu_table:map (callback) Iterates over the table calling callback(key, value) for each entry.

rcu

table ([size=256]) Creates a new RCU hash table.


Class rcu_table

RCU hash table object. Supports table-like access via __index and __newindex.

Usage:

local t = rcu.table()
t["key"] = true        -- boolean
t["n"]   = 42          -- integer
t["obj"] = data.new(8) -- object
print(t["key"])        -- true
t["key"] = nil         -- delete
rcu_table:__index (key)
Retrieves a value from the table (RCU-protected, lockless).

Parameters:

Returns:

    boolean, integer, object or nil
rcu_table:__newindex (key, value)
Sets or removes a value in the table (serialized). Assigning nil removes the entry.

Parameters:

  • key string
  • value boolean, integer, object or nil

Raises:

Error on memory allocation failure.
rcu_table:map (callback)
Iterates over the table calling callback(key, value) for each entry. Iteration is RCU-protected; order is not guaranteed.

Parameters:

  • callback function function(key, value).

Raises:

Error if callback raises.

rcu

table ([size=256])
Creates a new RCU hash table.

Parameters:

  • size integer Number of hash buckets (rounded up to power of two). (default 256)

Returns:

    rcu_table

Usage:

    local t = rcu.table()      -- 256 buckets (default)
    local t = rcu.table(8192)  -- 8192 buckets
generated by LDoc 1.5.0 Last updated 2026-03-31 12:21:45