Chapter 11
Threading Using Goroutines
IN THIS CHAPTER
Getting acquainted with goroutines
Working with goroutines when you have shared resources
Getting goroutines synchronized
In the previous chapters, all the Go statements that I show you are executed sequentially: A statement will execute only after the previous statement has finished executing. However, in real life, we often do things concurrently — for example, you can be driving and at the same time listening to a podcast, a receptionist can answer the phone while greeting visitors in a busy reception area, and so on.
In programming, concurrent programming is a technique that allows you to perform multiple tasks at the same time. Concurrent programming often requires the use of constructs such as threads and locks to perform synchronization and prevent deadlocks. It’s complex.
In Go, goroutines are functions that run concurrently with other functions. When you use goroutines, your program will be more responsive. You might use goroutines when performing tasks that deal with different input sources. For example, your program may need to interact with the users and at the same time need to communicate with backend servers through ...
Get Go Programming Language For Dummies 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.