Re: [go-nuts] sync/atomic and zero-initialization

2019-03-11 Thread 'Keith Randall' via golang-nuts
The garbage collector ensures that after it has zeroed memory, it does proper synchronization to hand off that memory to an allocator. That allocator (and the goroutine on whose behalf it is working) is then guaranteed to see the zeroed memory. That's how heap memory works. Stack memory is a sp

Re: [go-nuts] sync/atomic and zero-initialization

2019-03-11 Thread shivaram via golang-nuts
Thanks very much. For my own edification, could you give me some pointers (pun not intended) as to how the current runtime implementation ensures that uninitialized memory is never visible to any goroutine, even if the only synchronization used to read it is a sync/atomic primitive? On Monday,

Re: [go-nuts] sync/atomic and zero-initialization

2019-03-10 Thread Ian Lance Taylor
On Sun, Mar 10, 2019 at 7:54 PM shivaram via golang-nuts wrote: > > Can users of sync/atomic assume that memory will initially be zeroed? Or is > it necessary for a manual zeroing (using the atomic store operations) to > happen-before any reads? > > Context: https://github.com/golang/go/issues/5

[go-nuts] sync/atomic and zero-initialization

2019-03-10 Thread shivaram via golang-nuts
Can users of sync/atomic assume that memory will initially be zeroed? Or is it necessary for a manual zeroing (using the atomic store operations) to happen-before any reads? Context: https://github.com/golang/go/issues/5045 has the suggestion that "you shouldn't mix atomic and non-atomic access