On Tuesday, November 17, 2015 at 1:23:08 PM UTC-8, Ian Lance Taylor wrote:
On Tue, Nov 17, 2015 at 12:43 PM, Gbr <gbrose...@gmail.com <javascript:>>
Trying to figure out the idiomatic way of coordinating state management
among interacting goroutines using sync.Cond.
I think I would use the channels. sync.Cond is not at all common in Go

I don't really understand your code fragment or your question.
Scenario summary: lots of async goroutines running, any of which can affect
the running of a goroutine p that needs to wait for something 'important'
to happen. Tight coupling p with the other goroutines is naturally
undesirable. Lots of channels, each specific to the different goroutine
notifications, is equally undesirable.

sync.Cond appears to provide a simple wait point idiom. But with apparent
locking issues.

So, is this then the 'right' approach(untested)? I am guessing a bit about
what you and Tomas (re cancellation) are suggesting.

package sync

const (
     Resume Signal = iota

type Signal int

type Blocker interface {

type Block struct {
     sig chan Signal
     done chan bool
     blocker *Blocker

func NewBlock(br *Blocker) {
     return &Block{
         blocker: br,
         sig: make(chan Signal),
         done: make(chan bool),

func (b *Block) Alert(s Signal) {
     b.sig <- s

func (b *Block) Done() {

func (b *Block) Wait() {
     for {
         select {
         case sig := <-b.sig:
             switch sig {
             case Resume:
             case Fail:

         case <-b.done:

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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 6 | next ›
Discussion Overview
groupgolang-nuts @
postedNov 17, '15 at 8:43p
activeNov 18, '15 at 8:00p



site design / logo © 2022 Grokbase