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

A worker pool uses `sync.WaitGroup`. The code below occasionally reports 'WaitGroup is reused before previous Wait has returned' or misses jobs. What is the ordering bug?

var wg sync.WaitGroup for i := 0; i < n; i++ { go func() { wg.Add(1) defer wg.Done() work() }() } wg.Wait()