Readit News logoReadit News
xavierxwang commented on Put a ring on it: a lock-free MPMC ring buffer   h4x0r.org/ring/... · Posted by u/signa11
qbane · 3 months ago
By a quick glance, yes, this is what I want: a channel to communicate between processes via a piece of shared memory, protected by a pair of futexes.

In JS ecosystem, buffers that allow data loss is more common (aka ring buffers), but ringbuf.js [1] is the only complete implementation to my knowledge. In my use case on I/O between WASM modules where data must be transferred as-is, the process must block on buffer overrun/underrun in a synchronous manner. Therefore a circular buffer is required. I could not find such a niche library written in JS, so I decided to bite the bullet and reinvent the wheel [2].

[1]: https://github.com/padenot/ringbuf.js

[2]: https://github.com/andy0130tw/spsc

xavierxwang · 3 months ago
After a quick glance, it seems that you don’t maintain the reading/writing status in the shared memory. That means you have to make a syacall in every read/write call. You could look into the kaze-core for an alternative implementation, which doesn’t require any syscall if possible.

Btw, kaze-core uses a `used` atomic variable, to avoid reading both readPos/writePos in routine - they are not atomic at all.

xavierxwang commented on Put a ring on it: a lock-free MPMC ring buffer   h4x0r.org/ring/... · Posted by u/signa11
xavierxwang · 3 months ago
Is there any chance to modify Vyukov's MPMC queue implement (https://www.1024cores.net/home/lock-free-algorithms/queues/b...) to support drop handler? That work doesn't need 128 bit CAS.
xavierxwang commented on Put a ring on it: a lock-free MPMC ring buffer   h4x0r.org/ring/... · Posted by u/signa11
qbane · 3 months ago
I wrote my first SPSC circular buffer implementation in TS upon reading the previous post on futex [0] from the same author. It was more intricate than it had seemed, until I finally sat down and wrote my own code.

[0]: https://h4x0r.org/futex/ discussion: https://news.ycombinator.com/item?id=44951563

xavierxwang · 3 months ago
FYI: I have made a SPSC circular buffer for swap data in a pair of process: https://github.com/starwing/kaze-core

maybe that is what you want.

xavierxwang commented on Building Musubi: A diagnostic renderer ported from Rust to C with LLM Assistance   github.com/starwing/musub... · Posted by u/xavierxwang
xavierxwang · 3 months ago
I spent a month porting Rust's Ariadne diagnostic renderer to C, with Claude as a pair programming partner. The project taught me a lot about working with LLMs on real system programming tasks - what works, what doesn't, and where human expertise still matters.

u/xavierxwang

KarmaCake day4December 13, 2025View Original