Go WaitGroup: Difference between revisions
Jump to navigation
Jump to search
Line 6: | Line 6: | ||
=Overview= | =Overview= | ||
A <code>WaitGroup</code> is a [[Concurrent_(Parallel)_Programming#Counting_Semaphore|counting semaphore]] that waits for a set of goroutines to finish. The main goroutine calls <code>Add()</code> to set the number of goroutines to wait for. When each of the counted goroutines runs, they should call <code>Done()</code> when finished | A <code>WaitGroup</code> is a [[Concurrent_(Parallel)_Programming#Counting_Semaphore|counting semaphore]] that waits for a set of goroutines to finish. | ||
The main goroutine calls <code>Add()</code> to set the number of goroutines to wait for. Then it can block on <code>Wait()</code> until all other goroutines have finished. When each of the counted goroutines runs, they should call <code>Done()</code> when finished, to increment the counting semaphore. |
Revision as of 21:19, 1 September 2023
External
Internal
Overview
A WaitGroup
is a counting semaphore that waits for a set of goroutines to finish.
The main goroutine calls Add()
to set the number of goroutines to wait for. Then it can block on Wait()
until all other goroutines have finished. When each of the counted goroutines runs, they should call Done()
when finished, to increment the counting semaphore.