This book is meant for developers who have some experience with Go; I make no attempt to explain the basic syntax of the language. Knowledge of how concurrency is presented in other languages is useful, but not necessary.
By the end of this book we will have discussed the entire stack of Go concurrency concerns: common concurrency pitfalls, motivation behind the design of Gos concurrency, the basic syntax of Gos concurrency primitives, common concurrency patterns, patterns of patterns, and various tooling that will help you along the way.
Because of the breadth of topics well cover, this book will be useful to various cross-sections of people. The next section will help you navigate this book depending on what needs you have.
Navigating This Book
When I read technical books, I usually hop around to the areas that pique my interest. Or, if Im trying to ramp up on a new technology for work, I frantically skim for the bits that are immediately relevant to my work. Whatever your use case is, heres a roadmap for the book with the hopes that it help guide you to where you need to be!
This chapter will give you a broad historical perspective on why concurrency is an important concept, and also discuss some of the fundamental problems that make concurrency difficult to get correct. It also briefly touches on how Go helps ease some of this burden.
If you have a working knowledge of concurrency or just want to get to the technical aspects of how to use Gos concurrency primitives, its safe to skip this chapter .
This chapter deals with some of the motivational factors that contributed to Gos design. This will help give you some context for conversations with others in the Go community and help to frame your understanding of why things work the way they do in the language.
Here well start to dig into the syntax of Gos concurrency primitives. Well also cover the sync
package, which is responsible for handling Gos memory access synchronization. If you havent used concurrency within Go before and are looking to hop right in, this is the place to start.
Interspersed with the basics of writing concurrent code in Go are comparisons of concepts to other languages and concurrency models. Strictly speaking, its not necessary to understand these things, but these concepts help you to achieve a complete understanding on concurrency in Go.
In this chapter, we begin to look at how Gos concurrency primitives are composed together to form useful patterns. These patterns will both help us solve problems and avoid issues that can come up when combining concurrency primitives.
If youve already been writing some concurrent code in Go, this chapter should still prove useful.
In this chapter, we take the patterns we have learned and compose these into larger patterns commonly employed in larger programs, services, and distributed systems.
This chapter describes how the Go runtime handles scheduling goroutines. This is for those of you who want to understand the internals of Gos runtime.
The appendix simply enumerates various tools and commands that can help make writing and debugging concurrent programs easier.
Online Resources
Go has a very active and passionate community! For those newer to Go, take heart, it will be easy to find friendly, helpful people to guide you along on your path to Go. Here are a few of my favorite community-oriented resources for reading, getting help, and interacting with your fellow gophers:
https://golang.org/
https://golang.org/play
https://go.googlesource.com/go
https://groups.google.com/group/golang-nuts
https://github.com/golang/go/wiki
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.