Re:Optimizing a Ring Buffer for Throughput
by mananaysiempre on Tuesday June 27, 2023 @05:41AM
(#36490804)
I don’t get it. Both readIdx_ and writeIdxCached_ are “owned” by the consumer. (That being the point of a “cached” copy.) The producer might read readIdx_ occasionally, whenever we go through the whole buffer, but otherwise only the consumers access these. So why should we avoid putting them on the same cache line?
Re:Optimizing a Ring Buffer for Throughput
by gpderetta on Tuesday June 27, 2023 @05:33AM
(#36490768)
false sharing is the reason for splitting readIdx and writeIdx. But there is no reason to split readIdx and writeIdxCached.
Re:Optimizing a Ring Buffer for Throughput
by 4gotunameagain on Tuesday June 27, 2023 @05:27AM
(#36490719)
Yeap. The linked cpp ref doc has a nice example:
https://en.cppreference.com/w/cpp/thread/hardware_destructiv...
In the example you linked it's comparing two threads reading from the same or separate cache lines, no? If so, that's not really the point I was referring to (as the two variables I mentioned as example are accessed by a single thread, not by two threads).
https://stackoverflow.com/questions/22766191/what-is-false-s...