Concurrency
If there was one feature that would characterize Go amongst other popular programming languages, it would be concurrency. Go's built-in concurrency primitives — goroutines and channels are one of the best abstractions we know for writing efficient code that can run more than one task simultaneously.
Your program starts in the main goroutine, but at any point, you can spawn other concurrent goroutines and create communication channels between them. You can do this with considerably less effort and less code compared to other programming languages, which improves the developing experience and your code’s support.
In this section we cover the following concurrency primitives:
- Goroutines and the use of
sync
package for their coordination. - How we use channels to send and receive data between goroutines.
- The use of mutexes with data shared between different goroutines
Goroutines
One way to think of Goroutines is...