On Sun, Oct 30, 2022 at 08:47:41AM -0700,
jake...@gmail.com wrote:
> I would like to give you a definitive answer, but the same question comes
> up in
https://groups.google.com/g/golang-nuts/c/Gze1TRtdLdc/ and there is
> much disagreement and no clear resolution. (The initial question is not
> exactly yours, but if I understand correctly, the discussion quickly gets
> simplified to exactly yours.) So unless *someone from the go team is
> willing to clarify,* all you are getting are varying options. Of course,
> read the thread yourself and maybe you will believe one side was correct.
Thank you!
Somehow I missed that thread, and it is indeed very close to my situation.
An very interesting read - though not quite satisfying, alas ;-)
> Reading your description, I am also concerned that you could have a logical
> race. Its possible you already account for this, but if you are setting the
> 'array pointer' atomically and separately setting the 'count' atomically,
> the there could be cases where readers read a count not matching the
> current array. There are many simple fixes, and you hopefully have already
> taken this into account, but I just wanted to mention it.
Again, thanks!
Yes, there is a logical race, but in the real code the variable holding the
address of an array is written only once: the writer goroutine actually grows
a linked list, and the "active" array is the list's tail - in the same
compound variable with its length. So I _thought_ that any reader who managed
to get to the list's tail had no way reading the length from a different
array. (Trying to explain the whole construction I'm dealing with would
supposedly made it impenetrable for the readers so I've tried to simplify the
things as much as possible.)