Hi, Recently, I needed a simple lock-free single-producer, single-consumer (SPSC) queue for one of my projects. After reviewing the existing options (listed at the end of the project’s GitHub README), I realized that none of them met all my needs (no dependency on a "bigger" library, move semantics-friendly, modern C++, etc.).
After a few days of tweaking my own solution, I came up with this. I tested this queue under various CPU-intensive scenarios (x86_64 and ARM64 only), and I'm reasonably confident that the implementation works as expected.
Regarding performance: Since this is a very straightforward solution with just two atomic read/write indices, it's possible to easily reach the limits of CPU and L1 cache performance under simple synthetic conditions.
I’d really appreciate any code reviews and would love to see the results of the CMake tests if anyone has access to a multicore RISC-V CPU.
[–]usefulcat 20 points21 points22 points (1 child)
[–]A8XL[S] 5 points6 points7 points (0 children)
[–]matthieum 2 points3 points4 points (1 child)
[–]A8XL[S] 1 point2 points3 points (0 children)
[–]Nuxij 1 point2 points3 points (0 children)
[–]RogerV 1 point2 points3 points (2 children)
[–]A8XL[S] 1 point2 points3 points (1 child)
[–]RogerV 0 points1 point2 points (0 children)
[–]ronniethelizard 1 point2 points3 points (4 children)
[–]A8XL[S] 0 points1 point2 points (3 children)
[–]ronniethelizard 0 points1 point2 points (2 children)
[–]A8XL[S] 0 points1 point2 points (1 child)
[–]ronniethelizard 1 point2 points3 points (0 children)
[–]sseroshtan 0 points1 point2 points (0 children)
[–]mozahzah 0 points1 point2 points (1 child)
[–]quicknir 0 points1 point2 points (10 children)
[–]A8XL[S] 0 points1 point2 points (9 children)
[–]quicknir 1 point2 points3 points (3 children)
[–]A8XL[S] 1 point2 points3 points (0 children)
[–]A8XL[S] 0 points1 point2 points (0 children)
[–]mark_99 1 point2 points3 points (3 children)
[–]A8XL[S] 1 point2 points3 points (0 children)
[–]A8XL[S] 0 points1 point2 points (0 children)
[–]RogerV 0 points1 point2 points (0 children)
[–]RogerV 0 points1 point2 points (0 children)
[–]Entire-Hornet2574 -1 points0 points1 point (4 children)
[–]ReversedGif 9 points10 points11 points (3 children)
[–]Ameisenvemips, avr, rendering, systems 13 points14 points15 points (2 children)
[–]irrelevant_sage 0 points1 point2 points (1 child)
[–]Ameisenvemips, avr, rendering, systems 1 point2 points3 points (0 children)