Thank you for your reply, I agree there should be a memory barrier for the 
channel, for it is different from the other assignment statements and not a 
write operation. Have you got some readings talk about this?

On Tuesday, January 7, 2020 at 10:17:43 AM UTC+8, Kurtis Rader wrote:
>
> On Mon, Jan 6, 2020 at 5:47 PM hao dong <hao....@gmail.com <javascript:>> 
> wrote:
>
>> thanks for your reply. Could you guide me any readings or source code 
>> about channel of happens before.
>>
>
> I think you have misunderstood this text in the https://golang.org/ref/mem 
> document you linked to:
>
> Within a single goroutine, reads and writes must behave as if they 
>> executed in the order specified by the program. That is, compilers and 
>> processors may reorder the reads and writes executed within a single 
>> goroutine only when the reordering does not change the behavior within that 
>> goroutine as defined by the language specification. Because of this 
>> reordering, the execution order observed by one goroutine may differ from 
>> the order perceived by another.
>
>  
> The send on the channel is not a "write" operation in the sense meant by 
> the above text. Nor is the receive on the channel a "read" operation. That 
> paragraph is talking about reads and writes of memory in units (bytes, 
> words, etc.) supported by the CPU. Also, notice the "only when the 
> reordering does not change the behavior" portion of the above text. If the 
> compiler did the assignment after the send on the channel that would change 
> the behavior of the program. Channel ops are what are known as memory 
> barriers, and thus don't allow ops before or after the channel op to be 
> reordered before or after the op.
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
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/37c57f74-f736-4b12-bbb4-ddbac172ec74%40googlegroups.com.

Reply via email to