by pjdesno · 8mo ago · 0 comments
You dismissed the standard lock-guarded data structure as a "bogus comparison", despite it being the way every programmer is taught to write multi-threaded code.
Now the more you write, the more you seem to make the case that (a) normal programmers shouldn't be writing code like this, and (b) there are significant speedups possible if someone who knows what they're doing *does* write a highly tuned lock-free library.
std::array<T, N> buffer_;
alignas(64) absl::Mutex hmu_;
std::size_t head_{0};
std::size_t tail_cached_{0};
alignas(64) absl::Mutex tmu_;
std::size_t tail_{0};
std::size_t head_cached_{0};
Then change the code to forget the atomics and just use the locks. On my system this is more than ten times faster than the baseline naïve thread-safe RingBufferV2. That's what I mean about using a bogus baseline.