chapter five

5 Inter-process communication

 

In this chapter

  • You learn how to achieve effective task communication
  • You learn how to choose communication type for your applications
  • You learn a popular programming pattern for creating concurrent applications – Thread pool

We can't always guarantee that concurrent tasks running on a computer are independent. Often, communication between tasks is necessary for efficient execution. For example, if one task depends on the result of another, the application will have to know when to pause its work while it waits for the other tasks to finish.

Communication is therefore at the heart of any concurrent system. If we cannot ensure proper communication between tasks, the performance gains from concurrency are meaningless. In this chapter you will learn the concepts provided by the operating system to allow processes and threads to communicate with each other and to coordinate their work. We’ll start off by looking at the different types of communication you’re likely to encounter in a concurrent system.

5.1 Types of communication

The operating system provides mechanisms allowing processes and threads to communicate with each other. These mechanisms are called inter-process communication, or IPCs. Once you decide that your application will benefit from IPC, you must decide which of the available IPC methods on your system to use.

5.1.1 Shared memory IPC

5.1.2 Message passing IPC

5.2 Thread pool pattern

5.2.1 Cracking passwords revisited

5.3 Recap