Chapter 13Concurrency Primitives MeasuredPaid chapter

Channels — Implementation, Contention, the Memory Model, and Alternatives

Understand the runtime implementation of channels, their contention characteristics, the memory-model guarantee they provide, and when mutexes/atomics are measurably better.

Launch paywall

This chapter is part of the paid launch. The preview stays visible so readers can evaluate the exact scope before buying.

Included in

Core, Complete, and Team. Complete also includes the practical exam and free Go-version updates.

Preview

What this chapter teaches

Common belief

Channels are the idiomatic, fast way to share data; use them everywhere.

What actually happens

an hchan is a mutex-guarded struct; every send/receive locks, and unbuffered ops add a scheduler handoff. Under contention, mutexes/atomics are measurably faster. Channels' real value is the happens-before guarantee, not speed.

Mechanisms covered
Unbuffered channels require goroutine handoff via scheduler operations. Buffered channels avoid handoff when neither full nor empty, but still lock per operation.
Under contention, the channel lock is the bottleneck. Atomics and mutexes avoid scheduler coordination.
Memory model: a send happens-before the corresponding receive completes; this establishes ordering across goroutines. That guarantee — not throughput — is the reason to choose a channel.
benchexperiment
Email-first checkoutUnlock Chapter 13

Unlock Chapter 13 and the rest of the course.

Start with your email, then continue to Lemon Squeezy checkout. Core unlocks the paid chapters, Complete adds the exam and free Go-version updates, and Team gives you 5 seats.

Choose a plan

You'll head to Lemon Squeezy for secure checkout. Global tax is handled there. No subscription. Complete also includes the practical exam and free Go-version updates.

Free chapter
Escape Analysis — The Compiler's Fragile Decision
Understand how the compiler decides between stack and heap allocation, why the decision is fragile, and how to verify it.
Free chapter
Maps — Swiss Tables, Growth, and Permanent Memory
Understand the Go 1.24+ Swiss Table map layout, why maps don't shrink, and how to design for memory reclamation.