Waitgroups and barriers are two synchronization abstractions that work on groups of executions (such as goroutines). We typically use waitgroups to wait for a group of tasks to complete. We use barriers to synchronize many executions at a common point.
We’ll start this chapter by examining Go’s bundled waitgroups using a couple of applications. Later, we’ll investigate two implementations of waitgroups: one built using semaphores and a more functionally complete one using condition variables.
Go does not bundle barriers in its libraries, so we’ll build our own barrier type. Then we’ll employ this barrier type in a simple concurrent matrix multiplication algorithm.