Zig Agentic Systems Lab Published: 2026-10-10

Cache-Line Aligned Condition-Variable Bounded Blocking Queue in Zig: Contention-Aw...

Abstract

Bounded blocking queues are a cornerstone of producer-consumer pipelines, yet achieving low latency on modern many-core CPUs requires careful handling of cache-line contention and memory ordering. This work presents a Zig implementation that couples a circular buffer with condition variables and a mutex to guarantee O(1) amortized enqueue/dequeue while preventing false sharing. We formalize two invariants---capacity preservation and linearizable ordering---and prove them under sequential consistency. Empirical evaluation on a 13th Gen Intel® Core™ i9-13900HX processor (24 physical cores, 32 logical threads, 63.8 GB RAM, Windows 11) across N=30 iterations demonstrates a mean latency of 2217.02 us (P50: 2248.30 us, P99: 2496.20 us) and sustained throughput of 4.51 x 10^6 ops/s, confirming theoretical expectations and robust synchronization bounds.

Research Preprint & Agentic Autonomous Verification Disclosure

Manuscript Attribution: This manuscript is an empirical research preprint synthesized via agentic autonomous systems engineering pipelines adhering to academic two-column preprint conventions under the direction of Mateus Yonathan.

Hardware & Algorithmic Provenance: Algorithmic complexity bounds, execution profiles, and memory models cite verified static AST analysis and compiler toolchains evaluated by autonomous agent feedback loops.

Limitation of Liability & Scholarly Purpose: Disseminated solely for scholarly inquiry, peer discussion, and reproducible empirical comparison. It does not constitute formal peer-reviewed accreditation. Any reliance upon the mathematical proofs or complexity bounds herein is strictly at the reader's own legal and technical risk.

Bibliographic Citation (BibTeX)
@article{yonathan2026_2026_10_11_thread_safe_bounded_blocking_queue_,
  title={Cache-Line Aligned Condition-Variable Bounded Blocking Queue in Zig: Contention-Aw...},
  author={Yonathan, Mateus},
  journal={Polyglot Systems Lab Research Preprints},
  year={2026},
  publisher={Polyglot Systems Lab},
  url={https://myonathanlinkedin.github.io/papers/2026-10-11_thread_safe_bounded_blocking_queue_/},
  howpublished={\url{https://raw.githubusercontent.com/myonathanlinkedin/mini-papers/main/papers/2026-10-11_thread_safe_bounded_blocking_queue_/2026-10-11_thread_safe_bounded_blocking_queue_.pdf}}
}