Chapter 13Concurrency Primitives MeasuredPaid chapter

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

Compare synchronization workloads while preserving the ordering semantics each primitive provides.

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 and Complete. Complete also includes the practical exam and free Go-version updates.

Preview

What this chapter teaches

Common belief

Channels are the idiomatic, fast way for goroutines to share data. Prefer them over locks everywhere.

What actually happens

an hchan has a mutex, a ring buffer, and sender/receiver wait queues. Successful sends and receives acquire the lock; a failed non-blocking operation can return from an atomic fast path without it. An unbuffered operation pairs a sender and receiver directly, parking only when its counterpart is not already waiting. Under contention the channel machinery can become the bottleneck, so a sync.Mutex or sync/atomic is measurably faster for the counter measured here. Choose a channel for its communication, blocking, select, and happens-before semantics, and benchmark the actual workload.

Mechanisms covered
Channels supply specified synchronization ordering; the race detector checks executed paths rather than proving all paths safe.
Compare equivalent work and completion boundaries when timing channels, locks, and atomics.
benchexperiment
One-time purchase

Unlock Chapter 13 and the rest of the course.

Core unlocks every paid chapter and lab. Complete also includes the practical exam and future Go-version updates.

Core
$49

Full course access with the complete mechanics curriculum.

All paid chapters unlocked
One-time purchase
Perfect if you want the material only
Complete
$79
Best value

Best-value launch option with the exam and free Go-version course updates.

Everything in Core
Black Belt practical exam
Free Go-version updates

No subscription or account required. Access is tied to the email entered at Stripe Checkout and can be restored by email.

Free chapter
Escape Analysis: The Compiler's Fragile Decision
Distinguish escape diagnostics from measured allocations and explain the role of lifetime and call-site visibility.
Free chapter
Maps: Swiss Tables, Growth, and Permanent Memory
Distinguish map table capacity from referenced payloads and inspect clearing and growth on Go 1.25.