Deviopath › Go

sync.Once

Hard · Concurrency

sync.Once runs a function at most once, even when many goroutines call Do. Setup(n) should increment a shared counter inside Once from n goroutines.

Write RunOnce(n) that starts n goroutines each calling Do to add 1, and returns the counter (always 1 if n>=1, else 0).

Next: Same Binary Tree