ang-nuts
Subject: Re: [go-nuts] does Go memory model guarantee this program always
prints 1?
[Reply-To set; I don't need two copies of replies.]
* T L [170710 12:31]:
> so this is guaranteed by Go memory model?
>
> package main
>
> import "fmt"
> impor
* T L [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)
>
>
* T L [170710 12:32]:
> so this is guaranteed by go memory model?
>
> package main
>
> import "fmt"
> import "sync/atomic"
>
> func main() {
> var x, y int32
>
> atomic.AddInt32(&x, 1)
> atomic.AddInt32(&y, 1)
>
> if atomic.LoadInt32(&y) == 1 {
> fmt.Println("x
[Reply-To set; I don't need two copies of replies.]
* T L [170710 12:31]:
> so this is guaranteed by Go memory model?
>
> package main
>
> import "fmt"
> import "sync/atomic"
>
> func main() {
> var x, y int32
> go func() {
> atomic.AddInt32(&x, 1)
> atomic.AddInt32(&y,
On Monday, July 10, 2017 at 8:36:54 PM UTC+8, Jan Mercl wrote:
>
> On Mon, Jul 10, 2017 at 2:24 PM T L >
> wrote:
>
> > Aha, what I wanted to express is the execution orders of the two lines
> may be randomized.
> >
> > atomic.AddInt32(&x, 1)
> > atomic.AddInt32(&y, 1)
>
> No, assuming those
On Monday, July 10, 2017 at 8:36:54 PM UTC+8, Jan Mercl wrote:
>
> On Mon, Jul 10, 2017 at 2:24 PM T L >
> wrote:
>
> > Aha, what I wanted to express is the execution orders of the two lines
> may be randomized.
> >
> > atomic.AddInt32(&x, 1)
> > atomic.AddInt32(&y, 1)
>
> No, assuming those
On Monday, July 10, 2017 at 8:36:54 PM UTC+8, Jan Mercl wrote:
>
> On Mon, Jul 10, 2017 at 2:24 PM T L >
> wrote:
>
> > Aha, what I wanted to express is the execution orders of the two lines
> may be randomized.
> >
> > atomic.AddInt32(&x, 1)
> > atomic.AddInt32(&y, 1)
>
> No, assuming those
On Mon, Jul 10, 2017 at 2:24 PM T L wrote:
> Aha, what I wanted to express is the execution orders of the two lines
may be randomized.
>
> atomic.AddInt32(&x, 1)
> atomic.AddInt32(&y, 1)
No, assuming those two lines are as written, ie. part of single function
and thus executed in a single/the sa
On Sunday, July 9, 2017 at 5:10:20 PM UTC+8, Jan Mercl wrote:
>
> On Sun, Jul 9, 2017 at 10:56 AM T L >
> wrote:
>
> > But I remember that the "happens-before relationship" is never written
> down in any official Go documentation.
>
> https://golang.org/ref/mem#tmp_2
>
>
> --
>
> -j
>
Aha, wh
* T L [170709 04:56]:
> On Friday, July 7, 2017 at 8:42:28 PM UTC+8, Marvin Renich wrote:
> > Yes, the go routine establishes a happens-before relationship such that
> > x is incremented before y, and the atomic Add of y and Load of y ensure
> > that the Load either happens before or after, but
On Sun, Jul 9, 2017 at 10:56 AM T L wrote:
> But I remember that the "happens-before relationship" is never written
down in any official Go documentation.
https://golang.org/ref/mem#tmp_2
--
-j
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" grou
On Friday, July 7, 2017 at 8:42:28 PM UTC+8, Marvin Renich wrote:
>
> * T L > [170707 01:32]:
> > Then how about this?
> >
> > package main
> >
> > import "fmt"
> > import "sync/atomic"
> >
> > func main() {
> > var x, y int32
> > go func() {
> > atomic.AddInt32(&x, 1)
* T L [170707 01:32]:
> Then how about this?
>
> package main
>
> import "fmt"
> import "sync/atomic"
>
> func main() {
> var x, y int32
> go func() {
> atomic.AddInt32(&x, 1)
> atomic.AddInt32(&y, 1)
> }()
>
> if atomic.LoadInt32(&y) == 1 {
> fmt.Pr
T L,
No: https://github.com/golang/go/issues/19182
Peter
On Friday, July 7, 2017 at 5:31:33 AM UTC, T L wrote:
>
>
>
> On Friday, July 7, 2017 at 3:26:24 AM UTC+8, Lars Seipel wrote:
>>
>> On Thu, Jul 06, 2017 at 12:19:05PM -0700, T L wrote:
>> >
>> > package main
>> >
>> > import "fmt"
>>
> Then how about this?
No.
--
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.googl
On Friday, July 7, 2017 at 3:26:24 AM UTC+8, Lars Seipel wrote:
>
> On Thu, Jul 06, 2017 at 12:19:05PM -0700, T L wrote:
> >
> > package main
> >
> > import "fmt"
> > import "sync/atomic"
> >
> > func main() {
> > var x int32
> > atomic.AddInt32(&x, 1)
> > fmt.Println(atomic
On Thu, Jul 06, 2017 at 12:19:05PM -0700, T L wrote:
>
> package main
>
> import "fmt"
> import "sync/atomic"
>
> func main() {
> var x int32
> atomic.AddInt32(&x, 1)
> fmt.Println(atomic.LoadInt32(&x))
> }
Sure.
> Within a single goroutine, the happens-before order is the order
>
package main
import "fmt"
import "sync/atomic"
func main() {
var x int32
atomic.AddInt32(&x, 1)
fmt.Println(atomic.LoadInt32(&x))
}
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving e
18 matches
Mail list logo