Thanks for your caution. Then is there a way to know that a certain 
variable is aligned properly? Will the compiler make the global variable 
`var p *int` in my sample code aligned properly?

在 2017年1月9日星期一 UTC+8上午3:17:37,Dave Cheney写道:
>
> What you are talking about is called a torn write, which can occur if a 
> value is written to memory but not aligned properly as the processor or 
> memory subsystem must convert this write into two to correct for the miss 
> alignment. 
>
> Most processors that I know of, and all the ones that Go supports, 
> assuming that the value is correctly alligned will write the value 
> atomically, IE another processor will not see a partially written value. 
>
> However, I must caution you that while you say it is ok for one processor 
> to see an old value for a time, this is not how the Go memory model works. 
> There are no concessions for "for a time" and so on, the updated value may 
> never be written to memory, or the old value may continue to be visible for 
> the remainder of the program's run time. 
>
> The memory model describes what you ask for as a data race and states that 
> your program is no longer guaranteed to run correctly. Or put more 
> suscinctly, if you have a data race, the result of your program is 
> undefined. 
>
>

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