Re: [PATCH] Add thread safety to cRingBufferLinear

Udo Richter <[email protected]> Tue, 7 Feb 2023 00:54:16 +0100
Newsgroups gmane.linux.vdr
Message-ID <[email protected]>
On 06.02.23 23:29, Klaus Schmidinger wrote:
> It is supposed to be shared by *exactly* two threads.
> One only writing 'head', the other only writing 'tail'.

Two-ended buffers are pretty good when used correctly, but nowadays they
have a small chance of triggering memory ordering issues, where it is
possible that written data to the buffer is still stuck in a distant
cache, while the updated head pointer is already known to other CPU
cores. To be absolutely safe, the head pointer would need atomic
read/write, forcing ordering with a memory barrier.

But in general the timing for such a bug is pretty narrow, and advanced
CPUs (esp. intel/amd) make sure that things get stored in order anyway.
Worst thing would also just be false data read, not a crash.

Cheers,

Udo


_______________________________________________
vdr mailing list
[email protected]
https://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr