9 Programming with channels
This chapter covers
- Introducing communicating sequential processes
- Reusing common channel patterns
- Taking advantage of channels being first-class objects
Working with channels requires a different way of programming than when using memory sharing. The idea is to have a set of goroutines, each with its own internal state, exchanging information with other goroutines by passing messages on Go’s channels. In this way, each goroutine’s state is isolated from direct interference by other executions, reducing the risk of race conditions.
Go’s own mantra is not to communicate by shared memory but to instead share memory by communicating. Since memory sharing is more prone to race conditions and requires complex synchronization ...
Get Learn Concurrent Programming with Go now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.