import ( “fmt” “sync” “time” )

var ( done = false topic = “A” )

func main() { cond := sync.NewCond(&sync.Mutex{}) go Consumer(topic, cond) go Consumer(topic, cond) go Consumer(topic, cond) Push(topic, cond) time.Sleep(5 * time.Second)

}

func Consumer(topic string, cond *sync.Cond) { cond.L.Lock() for !done { cond.Wait() } fmt.Println(“topic is “, topic, “ starts Consumer”) cond.L.Unlock() }

func Push(topic string, cond *sync.Cond) { fmt.Println(topic, “starts Push”) cond.L.Lock() done = true cond.L.Unlock() fmt.Println(“topic is “, topic, “ wakes all”) cond.Broadcast() } ```