On Feb 7, 2015 12:40 PM, "tsuna" <tsun...@gmail.com> wrote:
>
> On Sat, Feb 7, 2015 at 12:13 PM, Dmitry Vyukov <dvy...@google.com> wrote:
> > On Sat, Feb 7, 2015 at 11:11 PM, tsuna <tsun...@gmail.com> wrote:
> >> Hi,
> >> I have to implement Go support for an existing system that uses shared memory.
> >>
> >> There are various places in the code where I have a loop in which I
> >> need to read some sort of a uint32 version number from shared memory,
> >> then read some more stuff, and read the version number again, and
> >> ensure it didn’t change (if it did, I loop again).
> >>
> >> I need to make sure the compiler doesn’t reorder the code as it
> >> optimizes things, so that the version number is indeed read before
> >> what follows.
> >>
> >> In the existing C++ implementation, we use asm volatile("" : : :
> >> "memory”) to ask the compiler to not reorder things, but I found
> >> nothing equivalent to this in Go.
> >
> >
> > Use sync/atomic.LoadUint32.
>
> I already use it. Why does it act like a compiler memory barrier?
It has to, or the runtime package wouldn't work as it must.
The sync/atomic functions probably ought to be in the memory model, but we're tired of arguing about the memory model doc.
Ian
Ø It has to, or the runtime package wouldn't work as it must.
Ø The sync/atomic functions probably ought to be in the memory model, but we're tired of arguing about the memory model doc.
You are saying that Go itself, and programs which use sync/atomic functions, would fail if it is not true. Yet it’s not guaranteed (documented)?
If I understand issue 5045 correctly, it would seem that the argument against the guarantee has been superseded (resolved?) by implementation. So why not now document this essential and often-questioned issue?
John
John Souvestre - New Orleans LA
From: golan...@googlegroups.com [mailto:golan...@googlegroups.com] On Behalf Of Ian Lance Taylor
Sent: 2015 February 07, Sat 21:27
To: tsuna
Cc: golang-nuts; Dmitry Vyukov
Subject: Re: [go-nuts] Compiler level memory barrier in Go i.e. asm volatile("" : : : "memory")
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
It doesn’t say which primitives in sync/atomic are sequentially consistent / memory barriers. Perhaps if it were clearer about this then it wouldn’t confuse so many users and even Go developers?
John
John Souvestre - New Orleans LA