Learn Concurrent Programming with Go cover
welcome to this free extract from
an online version of the Manning book.
to read more
or

2 Dealing with threads

 

This chapter covers

  • Modeling concurrency in operating systems
  • Differentiating between processes and threads
  • Creating goroutines
  • Differentiating between concurrency and parallelism

The operating system is the gatekeeper of our system resources. It decides when and which processes are given access to the various system resources, including processing time, memory, and network. As developers, we don’t necessarily need to be experts on the inner workings of the operating system. However, we need to have a good understanding of how it operates and the tools it provides to make our lives as programmers easier.

We’ll start this chapter by looking at how the operating system manages and allocates resources to run multiple jobs concurrently. In the context of concurrent programming, the operating system gives us various tools to help manage this concurrency. Two of these tools, processes and threads, represent the concurrent actors in our code. They may execute in parallel or interleave and interact with each other. We will look, in some detail, at the differences between the two. Later, we will also discuss goroutines and where they sit in this context, and then we’ll create our first concurrent Go program using goroutines.

2.1 Multiprocessing in operating systems

2.2 Abstracting concurrency with processes and threads

2.2.1 Concurrency with processes

2.2.2 Creating processes

2.2.3 Using multiprocessing for common tasks

2.2.4 Concurrency with threads

2.2.5 A multithreaded application in practice

2.5 Exercises

sitemap