Yes, I think you are right about the case in my sample code. The code 
doesn't show exactly what I'm concerned about. I just wanna know whether a 
write to a global pointer in 64-bit machine an atomic operation or not.

在 2017年1月9日星期一 UTC+8上午6:22:12,Caleb Doxsey写道:
>
> Shouldn't this particular case be ok? From the memory doc: 
> https://golang.org/ref/mem
>
> The go statement that starts a new goroutine happens before the 
>> goroutine's execution begins.
>
>
> So the write has to happen before the goroutine starts. At least that's 
> what the example indicates:
>  
>
>> For example, in this program: 
>
>  
>
> var a string
>
> func f() {
>
> print(a)
>
> }
>
> func hello() {
>
> a = "hello, world"
>
> go f()
>
> }
>
>  
>
>> calling hello will print "hello, world" at some point in the future 
>> (perhaps after hello has returned).
>
>
> On Sunday, January 8, 2017 at 1:17:56 PM UTC-5, 陈诚 wrote:
>
>> Is the size of a pointer value 32 bits or 64 bits in golang when build 
>> with `GOARCH=amd64` option specified and running on 64-bit OS?
>> If it's 64-bit size, is a global pointer value 8-byte aligned in memory 
>> so that a read or write operation of that pointer value is carried out 
>> atomically?
>> For example, in the following code, is it possible that the global 
>> pointer p is only partially updated when the read goroutine read the 
>> pointer?
>> var p *int
>>
>> void main() {
>>     i := 1
>>     p = &i
>>     go func() { fmt.Println(*p) } ()
>> }
>>
>> The scenario I'm concerning is that there is only one write but multiple 
>> reads on a global pointer value, and reading of an old value of the pointer 
>> is not important. Thanks in advance!
>>
>

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