Standard library / sync
sync.Cond.Broadcast()
Wake all current waiters; each reacquires L and rechecks the predicate. Expected stdout: 'ready\n'.
Formal Syntax & Structure
go syntaxgo
func (c *Cond) Broadcast()Working Example
Example Snippetgo
package main
import ( "fmt" "sync")
func main() { var mu sync.Mutex c := sync.NewCond(&mu) ready := false entered := make(chan struct{}) done := make(chan struct{}) go func() { mu.Lock() close(entered) for !ready { c.Wait() } mu.Unlock() close(done) }() <-entered mu.Lock() ready = true c.Broadcast() mu.Unlock() <-done fmt.Println("ready")}