# Ten simple Go concurrency examples

Run one example from the workspace root:

```sh
go run ./examples/concurrency/01-first-goroutine
```

Run every example:

```sh
for example in ./examples/concurrency/*/; do
  go run "$example"
done
```

Run one example with the race detector:

```sh
go run -race ./examples/concurrency/09-mutex-counter
```

The examples form a small progression:

1. Start one goroutine and wait for it.
2. Start several goroutines; observe that completion order is not guaranteed.
3. Send one value through an unbuffered channel.
4. Use a small buffered channel.
5. Close a channel and range until it is drained.
6. Express channel ownership with directional channel types.
7. Wait on communication or a timeout with `select`.
8. Distribute jobs through a small worker pool.
9. Protect a shared counter with `sync.Mutex`.
10. Protect a shared map with `sync.RWMutex`.

These programs require Go 1.25 or newer because they use `sync.WaitGroup.Go`.
See the [interactive lesson](../../lessons/0002-ten-simple-concurrency-examples.html)
for prediction prompts and explanations.
