Dave, you’re absolutely right about the possibility of losing channel on lines 43-47, in my use case that was not an issue because of serialized Notify calls.
On a second look I see a way to simplify my code essentially to this: https://play.golang.org/p/F8g-ltlXao <https://play.golang.org/p/F8g-ltlXao> , which I believe solves all shortcomings of the previous version. > On Nov 30, 2017, at 15:34, Dave Cheney <d...@cheney.net> wrote: > > thanks for sharing your implementation. I have a few questions. > > 1. is NewCond needed? Is this sufficient? > > var c Cond > c.Notify() > > 2. In notify, is the two arg form of the .(*barr) conversion necessary? If > the value is not initialised then the assertion to *barr will fail. If it is > initiased then the assertion will pass and therefore b is not nil. > > 3. I wonder if channels can be lost on line 43-47. For example like 44 > succceds and the first goroutine enters the block but has not yet reached > line 45, meanwhile a second goroutine enters line 43, fails the condition at > line 44 and then overwrites the value stored on line 47, then the first > goroutine completes the block and itself reaches line 47 overwriting the > value stored in the atomic value. At this point there may be two channels > being waited on by callers to Block, but one has been lost permanently. > > On Thursday, 30 November 2017 22:51:08 UTC+11, Artyom Pervukhin wrote: > Hi, > > Some time ago I had a similar use-case and came up with the following > pattern: https://play.golang.org/p/zQglq3ObvH > <https://play.golang.org/p/zQglq3ObvH> — it's based on guarantee that receive > operation on a closed channel always proceeds immediately. > > > -- > You received this message because you are subscribed to a topic in the Google > Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/Uxo-gS0qbqA/unsubscribe > <https://groups.google.com/d/topic/golang-nuts/Uxo-gS0qbqA/unsubscribe>. > To unsubscribe from this group and all its topics, send an email to > golang-nuts+unsubscr...@googlegroups.com > <mailto:golang-nuts+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- 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.