Multithreading with Pthreads Part I - Essentials

Have you downloaded a large file using a download-accelerator type of application? Have you played an online game? A flight simulator program? Used word processing, web browsers, Java apps, and so on? (The temptation to put in a smiley emoji here is high!)

It's quite likely that you have used at least some of these; so what? All of these disparate applications have something in common: it's highly likely that they are all designed for multithreading, meaning that their implementation uses multiple threads that run in parallel with each other. Multithreading has indeed become almost a way of life for the modern programmer.

Explaining a topic as large as multithreading is itself a big task; hence we are dividing the coverage into three separate chapters. This one is the first of them.

This chapter is itself logically divided into two broad parts: in the first, we carefully consider and understand the concepts behind the threading model—the what and why of multithreading. What exactly is a thread, why do we want threads, and a quick take on how multithreading has evolved on the Linux platform.

In the second part, we focus on the thread management APIs—the how (to some extent) of multithreading on Linux. The API set required to create and manage threads is discussed, with, of course, a lot of practical code to be seen and tried out.

At the outset of this topic, we must also clearly point out the fact that in this book we are only concerned with multithreading in the context of software programming; particularly, the POSIX threads (pthreads) implementation and specifically, pthreads on the Linux platform. We do not attempt to deal with various other multithreaded frameworks and implementations that have sprung up (such as MPI, OpenMP, OpenCL, and so on) or hardware threading (hyperthreading, GPUs with CUDA, and so on).

In this chapter, you will learn about programming with multiple threads on the Linux platform, specifically, getting started with the pthreads programming model or framework. This chapter is broadly divided into two parts:

  • In the first, key multithreading concepts—the what and the why of multithreading —are covered, laying the groundwork for the second part (and indeed the two subsequent chapters on multithreading).
  • The second part covers the essential pthreads APIs required to build a functional multithreaded application on Linux (it deliberately does not cover all aspects, through; the next two chapters will build on this one).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset