* T L <tapir....@gmail.com> [170710 12:35]:
> so this is guaranteed by Go memory model?
> 
> package main
> 
> import "fmt"
> import "sync/atomic"
> import "unsafe"
> 
> func main() {
>     var x, y int32
>     
>     var p = unsafe.Pointer(&x)
>     
>     atomic.AddInt32(&x, 1)
>     atomic.AddInt32(&y, 1)
>    
>     if atomic.LoadInt32(&y) == 1 {
>         fmt.Println("x =", *(*int32)(p)) // always 1 if it is printed?
>     }
> } 

Again, no concurrency.  Order is as written.

I've only used unsafe.Pointer once and in a way that was specifically
documented to work, and I have not otherwise researched it, so I may be
wrong here, but assuming the GC is guaranteed to update p if x moves,
then I believe this will always print "x = 1".

...Marvin

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