Go Channels Internals
summary
Walks the Go source to show exactly how channels work: three core structs — hchan with buffer, send/recv indices, mutex , pseudo-G and a waitQ linked list of blocked goroutines, plus the runtime send/receive paths. Demonstrates debug flags, the special-case of zero-sized empty structs, and why closed or new channels block or panic. Calls out the surprising detail that a send can write directly into another goroutine’s stack, and shows which runtime checks and queues make select, GC and scheduling interact with channels.
AI-written summary · about
chapters (17)
- 0:00Introduction to channels
- 1:23Channel basics and examples
- 3:23Channel characteristics
- 4:32Theoretical background (CSP)
- 5:53Internal channel structs
- 8:05Data structures and locking
- 10:48Memory allocation of channels
- 11:43Detailed analysis of hchan
- 15:52Wait queues and goroutines
- 17:28Wait queue example
- 20:09Source code demo
- 22:52Sending and receiving data
- 26:16Closing and edge cases
- 28:25The select statement
- 28:59Advanced channel usage
- 30:28Conclusion and resources
- 31:27Q&A
