Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumGoworker pool patternSingle-choice MCQ

In a worker pool, the workers read jobs from a channel and send results to a results channel. The code below deadlocks. What is the root cause?

func main() { jobs := make(chan int) results := make(chan int) for w := 0; w < 3; w++ { go func() { for j := range jobs { results <- j * 2 } }() } for j := 0; j < 5; j++ { jobs <- j } close(jobs) for r := 0; r < 5; r++ { fmt.Println(<-results) } }