4 Building blocks of concurrency

 

In this chapter:

  • You learn more about the middle layer of concurrency: the runtime system, a popular example of which is the operating system
  • You learn the internals of the two basic concurrency abstractions: threads and processes
  • You learn how to implement concurrent applications using threads and processes
  • You learn how to choose the concurrency abstraction suitable for your problem

Concurrent programming involves breaking down applications into independent units of concurrency. In previous chapters, we referred to these units as tasks for organizing the flow of the application. Now, with knowledge of the hardware being used, we need to map these abstractions onto the physical devices executing the code. Fortunately, another layer of abstraction can handle this task: the OS. Its role is to apply the available hardware as efficiently as possible, but it is not a magical solution. This chapter focuses on how developers can structure their programs to aid the OS in achieving optimal hardware utilization.

Concurrent programming steps

Processes

Process internals

Process states

Multiple processes

Threads

Thread features

Thread implementation

Recap