by bigdubs · 2y ago · 0 comments
Separately; the simulator is cool and very helpful!
Also this one enqueue will be mega expensive - a clear "fat tail" in the latency histogram.
In MultiArrayQueue you keep all already enqueued material in-place, "just" allocate the bigger array, register the new diversion, enqueue the one new element - and done.
Thanks
for me it would be better to allocate new buffer but allow reading from old one until it contains data and after that dealocate it and keep only new one in use
One other thing I want to shout out, I saw what I thought was a really neat multicast ring buffer the other day where the author has an atomic for each element, rather than the typical reader/writer atomics. The promise was having much less contention on any given atomic, in most cases. https://github.com/rezabrizi/SPMC-Queue https://news.ycombinator.com/item?id=40410172
You never know how many concurrent threads still "are" on the place you wish to remove.
You would have to deal with stuff like hazard pointers, limbo lists and the like.
Better to keep the small arrays there.
[0] It needs a refactor, but here's some version of the idea. https://github.com/hmusgrave/zcirc
[1] You're not _really_ bounded since you have blocking calls to the underlying allocator (usually somewhere close to the OS, and even that can do more work than you might expect when you ask for a contiguous array), but it's still much cheaper than a bulk copy.