On Fri, Mar 11, 2022 at 9:26 AM Brian Candler <b.cand...@pobox.com> wrote: > > On Friday, 11 March 2022 at 15:52:04 UTC Gregg Townsend wrote: >> >> Two concurrent calls of Put can load identical head and tail values and then >> store in the same slot. > > > Correct, but that's not a valid way to use this code. See > https://github.com/QuantumLeaps/lock-free-ring-buffer#lock-free-restrictions > > "The ring buffer does not require any "locking" (mutual exclusion mechanism) > as long as the following restrictions are met: > > Only one thread/interrupt can produce data into the ring buffer > Only one thread/interrupt can consume data from the ring buffer > > In other words, a given LFRB can be used only by one pair of producer/ > consumer threads/interrupts. Fortunately, this is the most frequently > encountered scenario."
I haven't looked at the web page, but OK, I think that can work if the memory loads and stores are correctly ordered, *provided* you take steps to ensure that the goroutine stays on the same CPU core. By default nothing guarantees that, and there is no portable way to require it. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUTZ%2BK0wPO5oRW0Vyu94fgEOsDX9FG3OL5qN6ab5cuoJg%40mail.gmail.com.