Module 08 of 12

Concurrency Patterns

Lessons

About This Module

Once you can start goroutines and pass values over channels, the next step is using them well. A handful of patterns show up in almost every real Go program, and knowing them helps you write concurrent code that is correct, predictable and easy to stop.

This module starts with select, which lets a goroutine wait on several channels at once. It then covers the worker pool pattern for processing many jobs with a fixed number of goroutines, mutexes for protecting shared data, and the context package for cancellation and timeouts.

Watch the lessons in order and try combining the patterns in one small program, then continue on to Standard Library & I/O.

Lessons

4 videos
01

Mastering select and for-select

Using select to wait on multiple channels, and the common for-select loop pattern built on top of it.

02

Go Concurrency: Master the Worker Pool Pattern for Efficient Job Processing

The worker pool pattern: spreading jobs across a fixed set of goroutines using channels.

03

Go Mutex Tutorial: Protect Shared Data with sync.Mutex & RWMutex

Protecting shared data from race conditions using sync.Mutex and RWMutex.

04

Go Context Package: Cancellation, Timeouts & Concurrent Programming

Using the context package to cancel work and set timeouts across goroutines.