Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-08-17 Thread robert engels
Sorry Ian, I see you included this - I was typing the message and replied without reading the refresh. > On Aug 17, 2020, at 6:59 PM, robert engels wrote: > > See https://github.com/golang/go/issues/5045 > which has been open for 7+ years. > >> On Au

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-08-17 Thread robert engels
See https://github.com/golang/go/issues/5045 which has been open for 7+ years. > On Aug 17, 2020, at 4:15 PM, Ian Lance Taylor wrote: > > On Mon, Aug 17, 2020 at 9:06 AM jake...@gmail.com wrote: >> >> My understanding is that atomic does not 'synchro

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-08-17 Thread Ian Lance Taylor
On Mon, Aug 17, 2020 at 9:06 AM jake...@gmail.com wrote: > > My understanding is that atomic does not 'synchronize memory' in general. If > you use a Mutex, then everything that happened before is 'synchronized'. If > you use atomic then only the atomic variable is 'synchronized'. That is kind

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-08-17 Thread Brian Candler
Sorry, I should have been clearer: sync.atomic *does* synchronize the memory that it references. I didn't mean to imply that it synchronizes all memory. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop re

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-08-17 Thread jake...@gmail.com
On Monday, August 17, 2020 at 11:19:16 AM UTC-4 b.ca...@pobox.com wrote: > On Monday, 17 August 2020 11:54:55 UTC+1, leo.b...@npo-data.nl wrote: >> >> E.g. A co-worker pointed out that you can avoid sync.Mutex by using this >> construct: >> >> if !atomic.CompareAndSwapInt32(&s.myLock, 0,

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-08-17 Thread Brian Candler
On Monday, 17 August 2020 11:54:55 UTC+1, leo.b...@npo-data.nl wrote: > > E.g. A co-worker pointed out that you can avoid sync.Mutex by using this > construct: > > if !atomic.CompareAndSwapInt32(&s.myLock, 0, 1) { > fmt.Println("locked") > return > }

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-08-17 Thread leo.b...@npo-data.nl
Playing Devil's Advocate: https://golang.org/ref/mem says: > To serialize access, protect the data with channel operations or other synchronization primitives such as those in the sync and sync/atomic packages. So it explicit

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-08-17 Thread Jesper Louis Andersen
On Mon, Aug 17, 2020 at 12:54 PM leo.b...@npo-data.nl < leo.bal...@npo-data.nl> wrote: > Thanks. So I take it this must be handled by the compiler when generating > assembly. > > Yes. The compiler generally follows the Go Memory Model reference specification: https://golang.org/ref/mem > E.g. A

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-08-17 Thread Jan Mercl
On Mon, Aug 17, 2020 at 12:55 PM leo.b...@npo-data.nl wrote: > Thanks. So I take it this must be handled by the compiler when generating > assembly. > > I have peeked in the src/cmd/compile/ directory , assuming it is hidden > there, but that's a rabbit hole I do want to go in just yet. > > Wha

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-08-17 Thread leo.b...@npo-data.nl
Thanks. So I take it this must be handled by the compiler when generating assembly. I have peeked in the src/cmd/compile/ directory , assuming it is hidden there, but that's a rabbit hole I do want to go in just yet. What I am really looking for is knowing which instructions lead to memory-syn

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-06-15 Thread Jan Mercl
On Mon, Jun 15, 2020 at 6:30 PM Leo Baltus wrote: > > from gopl chapter 9.4 'Memory synchronisation’ > > Synchronization primitives like channel communications and mutex operations > cause the processor to flush out and commit all its accumulated writes so > that the effects of goroutine executi

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-06-15 Thread burak serdar
On Mon, Jun 15, 2020 at 10:30 AM Leo Baltus wrote: > > from gopl chapter 9.4 'Memory synchronisation’ > > Synchronization primitives like channel communications and mutex operations > cause the processor to flush out and commit all its accumulated writes so > that the effects of goroutine execut

Re: [go-nuts] Memory synchronization by channel operations and mutexes

2020-06-15 Thread Robert Engels
Depends on the processor but usually it entails a “fence” instruction. > On Jun 15, 2020, at 11:31 AM, Leo Baltus wrote: > > from gopl chapter 9.4 'Memory synchronisation’ > > Synchronization primitives like channel communications and mutex operations > cause the processor to flush out and c