9 Concurrency: Practice

This chapter covers

  • Preventing common mistakes with goroutines and channels
  • Understanding the impacts of using standard data structures alongside concurrent code
  • Using the standard library and some extensions
  • Avoiding data races and deadlocks

In the previous chapter, we discussed the foundations of concurrency. Now it’s time to look at practical mistakes made by Go developers when working with the concurrency primitives.

9.1 #61: Propagating an inappropriate context

Contexts are omnipresent when working with concurrency in Go, and in many situations, it may be recommended to propagate them. However, context propagation can sometimes lead to subtle bugs, preventing subfunctions from being correctly executed.

Let’s consider ...

Get 100 Go Mistakes and How to Avoid Them 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.