On 13 September 2016 at 10:33, 'Paul Borman' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> That said, a map is represented by a single machine word (32 or 64 bits).
> I don't know of any modern architecture where reading a cache aligned word
> while it is being written will yield anything but the old or new value.
>

This line of reasoning is what leads to trouble.  The atomicity problem is
not with the map reference, which will be either old or new, but with all
the memory writes to the actual hash table, which may be in any number of
intermediate states including "impossible" ones.  You must ensure that the
completion of those writes happens before another goroutine attempts to
read from the hashtable, and for that, you need some kind of barrier: a
channel, mutex, or atomic.Value.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to