Re: [go-nuts] sync.Cond implementation

2018-04-18 Thread Penguin Enormous
Much appreciated for all the great advises from everyone. Or to be more precise: it is crucial you load wait before notify and the > check for equality can only happen if the routine "caught up". Also, your > proof must hold if you remove the fast-path check in line 522. > Why is it crucial to

Re: [go-nuts] sync.Cond implementation

2018-04-16 Thread Ian Lance Taylor
On Sat, Apr 14, 2018 at 10:02 AM, Penguin Enormous wrote: > > Could it be this: > > Initially wait == notify == 0 > > Waiter Signaler > > 479 atomic.Xadd(&l.wait, 1) = 1 > > 522 atomic.Load(&l.wait) = 0 > atomic.Load(&l.notify) = 0 > > 523 retur

Re: [go-nuts] sync.Cond implementation

2018-04-16 Thread Jesper Louis Andersen
There is a simple flowchart pertaining to data races: First question: Does your program have a data race? If no, everything is perfect. If yes, read on. Second question: Does your program have a performance problem? If no, then fix the race! If yes, then read on. Third question: There is no third

Re: [go-nuts] sync.Cond implementation

2018-04-16 Thread jake6502
On Monday, April 16, 2018 at 7:08:27 AM UTC-4, Jesper Louis Andersen wrote: > > On Sat, Apr 14, 2018 at 7:02 PM Penguin Enormous > wrote: > >> But looking at your answer, I see that you may imply certain race >> conditions are allowed. Could you explain a bit more on that? Aren't race >> conditi

Re: [go-nuts] sync.Cond implementation

2018-04-16 Thread Jesper Louis Andersen
On Sat, Apr 14, 2018 at 7:02 PM Penguin Enormous wrote: > But looking at your answer, I see that you may imply certain race > conditions are allowed. Could you explain a bit more on that? Aren't race > conditions supposedly bad? > > Race conditions can, in certain cases, be benign if guarded prop

Re: [go-nuts] sync.Cond implementation

2018-04-14 Thread Penguin Enormous
Could it be this: Initially wait == notify == 0 Waiter Signaler 479 atomic.Xadd(&l.wait, 1) = 1 522 atomic.Load(&l.wait) = 0 atomic.Load(&l.notify) = 0 523 return (because those above are equal) 485 notifyListWait(l, t) (blocked forever) But looking at your answer, I see that you may imply c

Re: [go-nuts] sync.Cond implementation

2018-04-13 Thread Ian Lance Taylor
On Thu, Apr 12, 2018 at 11:09 PM, Penguin Enormous wrote: > > Hi Gophers! > > I'm trying to understand line 522 of src/runtime/sema.go: > >> if atomic.Load(&l.wait) == atomic.Load(&l.notify) { >> >> ... > > > I can't help but thinking, what guarantee that the atomic read of l.wait > won't return s

[go-nuts] sync.Cond implementation

2018-04-12 Thread Penguin Enormous
Hi Gophers! I'm trying to understand line 522 of src/runtime/sema.go : if atomic.Load(&l.wait) == atomic.Load(&l.notify) { > > ... I can't help but thinking, what guarantee that the atomic read of l.wait won't return s