sync.WaitGroup
- Go by Example: WaitGroups
To wait for multiple Goroutine to finish, we can use a wait group.
A WaitGroup must not be copied after first use.
Share memory by communicating, don’t communicate by sharing memory
mutex
Normal
FIFO, competes with currently running Goroutine As running goroutine already has CPU cores, it is more likely to acquire the lock (better performance)
Starvation
New goroutine goes to FIFO queue
sync.Cond
Cond
implements a conditional variable that can be used in scenarios where multiple Readers are waiting for a shared resource ready (if there is only one read and one write, a lock or Go Channel takes care of it).