Challenge 3 — Solution Task: Write a function worker(id int, wg *sync.WaitGroup) that prints "Worker started" and "Worker finished" with the id, using defer wg.Done(). Launch 4 workers using a sync.WaitGroup, then print "All done" only after wg.Wait() returns. package main import ( "fmt" "sync" ) func worker(id int, wg *sync.WaitGroup) { defer wg.Done() fmt.Println("Worker", id, "started") fmt.Println("Worker", id, "finished") } func main() { var wg sync.WaitGroup for i := 1; i <= 4; i++ { wg.Add(1) go worker(i, &wg) } wg.Wait() fmt.Println("All done") } Expected output (worker order may vary, but "All done" is always last): Worker 2 started Worker 2 finished Worker 1 started Worker 4 started Worker 4 finished Worker 1 finished Worker 3 started Worker 3 finished All done Notes: - wg.Add(1) is called once per worker BEFORE launching it, so the WaitGroup's internal counter correctly reaches 4 before any worker has a chance to call Done(). - defer wg.Done() guarantees Done() runs when worker() returns, which is what eventually brings the counter back down to 0. - wg.Wait() blocks main() until that counter hits 0 — this is why "All done" is guaranteed to print last, even though the order of the workers' own output is unpredictable.