On Monday, August 15, 2022 at 9:50:17 AM UTC-7 jake...@gmail.com wrote:

> On Monday, August 15, 2022 at 5:20:58 AM UTC-4 ma...@changkun.de wrote:
>
>> Atomic operations on a and b are two different statements. It remains 
>> unclear where exactly is the sentence that tries to say this: atomic 
>> operations on different memory locations obey the program statements 
>> order within a goroutine. 
>>
>
> Doesn't the Section on Atomics <https://go.dev/ref/mem#atomic> statement 
> say just that:
>
> The APIs in the sync/atomic <https://go.dev/pkg/sync/atomic/> package are 
> collectively “atomic operations” that can be used to synchronize the 
> execution of different goroutines. If the effect of an atomic operation 
> *A* is observed by atomic operation *B*, then *A* is synchronized before 
> *B*. All the atomic operations executed in a program behave as though 
> executed in some sequentially consistent order.  
>
> Is your confusion about the term "observed"?
>

If it's helpful for anyone -

For a speculative / out-of-order processor, implementing the ISA involves 
microarchitecture that reorders everything. For loads and stores in 
particular the strategy can mean something like extremely aggressive 
reordering when instructions enter the pipeline, and invalidation or 
flushing later on. Keeping various (documented or undocumented) buffers or 
caches coherent is costly in pipelines, and there's a range of approaches 
to implementing pipelines that result in different implications here. With 
this in mind it's not just the compiler reordering things that is worth 
worrying about, but also the interaction of reordering schemes, which can 
become practically inexplicable without some conceptual coordination.

The language memory models really are a response to hardware "innovation". 
Saying "All the atomic operations executed in a program behave as though 
executed in some sequentially consistent order." is somewhat declarative. 
It's not a principle that simply emerges from implementation, but a 
description of behavior that can be reasoned about, unlike actual 
implementation. 

-- 
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/ea01011f-056d-42fd-afc8-3501e8f9fc49n%40googlegroups.com.

Reply via email to