You are misreading this. a) it implicitly refers to a single architecture
and b) it doesn't say that single-word accesses are atomic, it says that
multi-word accesses are inherently non-atomic. Making it a single-word
access is necessary but not sufficient, to actually get atomic reads/writes
you need to use sync/atomic <https://godoc.org/sync/atomic> (and I don't
understand why questions about which accesses are atomic keep coming up on
golang-nuts and /r/golang and the like, when there exists a method that
*gives* you atomic accesses in the best way possible for any given
architecture).

On Wed, Jul 6, 2016 at 5:32 PM, T L <tapir....@gmail.com> wrote:

> http://research.swtch.com/gorace
>
>
>> ...
>>
> The race is fundamentally caused by being able to observe partial updates
>> to Go's multiword values (slices, interfaces, and strings): the updates are
>> not atomic.
>>
>> The fix is to make the updates atomic. In Go, the easiest way to do that
>> is to make the representation a single pointer that points at an immutable
>> structure. When the value needs to be updated, you allocate a new
>> structure, fill it in completely, and only then change the pointer to point
>> at it. This makes the assignment atomic: another goroutine reading the
>> pointer at the same time sees either the new data or the old data, but not
>> a mix, assuming the compiler is careful to read the pointer just once and
>> then access both fields using the same pointer 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.
>

-- 
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