Concurrency
Concurrency is a core part of the Go language. Unlike many other languages that support concurrency via rich multi-threading libraries, Go provides relatively few language primitives to write concurrent programs.
Let’s start by emphasizing that concurrency is not parallelism. Concurrency is about how you write programs; parallelism is about how programs run. A concurrent program specifies what parts of the program can run in parallel. Depending on the actual execution, concurrent parts of a program may run sequentially, concurrently using time-sharing, or in parallel. A correct concurrent program yields the same result regardless of how it is run.
This chapter introduces some of the Go concurrency primitives using recipes. In this chapter, you will learn about the following:
- Creating goroutines
- Running multiple independent functions concurrently and waiting for them to end
- Sending and receiving data using channels
- Sending data to a channel...