6 Synchronizing with waitgroups and barriers

This chapter covers

  • Waiting for completed tasks with waitgroups
  • Building waitgroups with semaphores
  • Implementing waitgroups using condition variables
  • Synchronizing concurrent work using barriers

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 ...

Get Learn Concurrent Programming with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.