eakova/zigbeam
Zig-Beam: Reusable building blocks for high-performance concurrency and parallel computing
This repository hosts multiple Zig libraries under one roof. Each library can be used on its own or together via a common wrapper. The workspace is designed to be practical: every library ships with small samples, focused tests, and repeatable benchmarks.
@import("zigbeam").Libs.Arczig build samples-arczig build test-arcArc(T).Inner allocations; fronted by ThreadLocalCache and global Treiber stack@import("zigbeam").Libs.ArcPoolzig build test-arc-pool@import("zigbeam").Libs.ArcCycleDetectorzig build test-arc-cycle@import("zigbeam").Libs.ThreadLocalCachezig build samples-tlczig build test-tlc@import("zigbeam").Libs.TaggedPointerzig build samples-taggedzig build test-taggedSegmentedQueue as its EBR engine; not exposed via beam.Libszig build samples-ebrzig build test (full suite, includes EBR coverage)@import("zigbeam").Libs.DVyukovMPMCQueuezig build samples-dvyukovzig build test-dvyukov@import("zigbeam").Libs.ShardedDVyukovMPMCQueuezig build test-dvyukov@import("zigbeam").Libs.Dequezig build test-beam-dequezig build bench-beam-deque@import("zigbeam").Libs.DequeChannelzig build test-beam-deque-channelzig build bench-beam-deque-channelbeam-backoff module from the package and use Backoff directlybeam-cache-padded module from the package and use CachePadded directly@import("zigbeam").Libs.Taskzig build test-beam-task@import("zigbeam").Libs.BoundedSPSCQueuezig build test-spsc-queuezig build bench-spsc-queue@import("zigbeam").Libs.SegmentedQueuezig build test-segmented-queuezig build bench-segmented-queuesrc/libs/ — Concurrent programming primitives and data structuresYou can consume libraries from this repo via Zig's package system (recommended) or by vendoring the code. Below shows the package approach with the zigbeam wrapper module (which exposes all libraries under Libs).
build.zig.zon// build.zig.zon (top-level of your app)
.{
.name = "your-app",
.version = "0.1.0",
.dependencies = .{
.zigbeam = .{
// Track a tag or commit tarball (recommended)
.url = "https://github.com/eakova/zigbeam/archive/refs/heads/main.tar.gz",
// Compute and fill the content hash:
// zig fetch https://github.com/eakova/zigbeam/archive/refs/heads/main.tar.gz --save
.hash = "<fill-with-zig-fetch-output>",
},
},
}
Tip: run zig fetch <url> --save to automatically compute and insert the hash.
build.zigconst std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Declare a dependency on zigbeam package
const beam_dep = b.dependency("zigbeam", .{ .target = target, .optimize = optimize });
const beam = beam_dep.module("zigbeam");
// Example: an executable that imports zigbeam
const exe = b.addExecutable(.{
.name = "your-app",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zigbeam", beam);
b.installArtifact(exe);
}
// src/main.zig
const std = @import("std");
const beam = @import("zigbeam");
pub fn main() !void {
// Tagged pointer
const TaggedPointer = beam.Libs.TaggedPointer;
// Thread-local cache
const ThreadLocalCache = beam.Libs.ThreadLocalCache;
// Arc core and pool
const Arc = beam.Libs.Arc;
const ArcPool = beam.Libs.ArcPool;
// Beam-Ebr (Epoch-Based Reclamation)
const BeamEbr = beam.Libs.BeamEbr;
// DVyukov MPMC Queue
const DVyukovMPMCQueue = beam.Libs.DVyukovMPMCQueue;
const ShardedDVyukovMPMCQueue = beam.Libs.ShardedDVyukovMPMCQueue;
// Work-stealing deque and channel
const Deque = beam.Libs.Deque;
const DequeChannel = beam.Libs.DequeChannel;
// Cancellable task abstraction
const Task = beam.Libs.Task;
// Lock-free queues
const BoundedSPSCQueue = beam.Libs.BoundedSPSCQueue;
const SegmentedQueue = beam.Libs.SegmentedQueue;
// minimal smoke check
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit();
const alloc = gpa.allocator();
var arc_u64 = try Arc(u64).init(alloc, 42);
defer arc_u64.release();
std.debug.print("arc.get() = {}\n", .{arc_u64.get().*});
}
zig_beam wrapper re-exports the main libraries under Libs for easy access: Arc, Arc Pool, Arc Cycle Detector, Thread-Local Cache, Tagged Pointer, Backoff, DVyukov MPMC Queue, Sharded DVyukov, Deque, DequeChannel, Task, BoundedSPSCQueue, and SegmentedQueue.OS support: macOS, Linux, Windows
std.Thread, std.time, std.fs, std.atomic).-Dtarget if you need artifacts for another OS/arch.Zig version policy: Requires Zig 0.15.2 or later.
src/ — library code (keep public API in files imported by the library’s build.zig)src/libs/<lib>/ — individual libraries (code, tests, samples, benchmarks, docs)docs/ — high-level documentation and meta-notes_..._samples.zig with pub fn main() !void so they can run via zig run_..._unit_tests.zig, _..._integration_tests.zig, _..._fuzz_tests.zig (as applicable)_..._benchmarks.zig under src/libs/<lib>/benchmarks/, write Markdown results into that directory and print a short console summarysrc/libs/<lib>/ with:/<lib>.zig (public API surface)tests/, samples/, benchmarks/, and docs/ subdirectoriesbuild.zig by:createModulestest_specsbench_specs (if you provide benchmarks)samples/_..._samples.zig) with main()src/libs/<lib>/README.md or docs file with description and commandsContributions are welcome in the form of issues, PRs, and feedback. Please include:
Good first steps:
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Issues and PRs are welcome. Please include: