* Robert Engels <reng...@ix.netcom.com> [190301 15:07]: > I am pretty sure it is the memory model unless there is other code in > the stdlib that sets the dove back to nil - which wouldn’t make sense > since the channel should be unique to the context instance and that > would allow multiple done channels to be created.
I don't understand what you are saying. I absolutely agree that the memory model is what determines whether the OP's code is correct or not. What I was saying was that any ambiguity or lack of specificity in the memory model is not relevant to this case. I was referring to this statement: * Robert Engels <reng...@ix.netcom.com> [190301 08:57]: > This is actually a weakness due to the memory model of Go not being > fully specified IMO. The current memory model does not allow the compiler to move code that is written after a synchronization point to before that synchronization point. Under "Happens Before" in the memory model: Within a single goroutine, the happens-before order is the order expressed by the program. If you can show a reordering of the OP's code that the current memory model is not specific enough to disallow that would cause his code to not work as intended, then I will agree with you. >> * dongshujin.be...@gmail.com <dongshujin.be...@gmail.com> [190301 08:50]: >> 1 > func (c *cancelCtx) Done() <-chan struct{} { >> 2 > c.mu.Lock() >> 3 > if c.done == nil { >> 4 > c.done = make(chan struct{}) >> 5 > } >> 6 > c.mu.Unlock() >> 7 > return c.done >> 8 > } I do remember a while back there was considerable discussion about whether or not the memory model was ambiguous about certain things, and I was left unconvinced either way; in other words, this juror is still accepting evidence. However, in this specific case, in a specific instance of a goroutine whose execution has progressed to line 7, every write to c.done can either be proved to be the assignment on line 4 of that same goroutine, or can be proved to happen-before the lock on line 2 of that same goroutine is acquired. The current memory model is not ambiguous about this case. ...Marvin -- 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.google.com/d/optout.