Chapter 2. Multithreaded Programming
2.1 Why Threads?
2.2 Programming with Threads
2.2.1 Thread Creation and Termination
2.2.1.1 Creating POSIX Threads
2.2.1.2 Creating Win-32 Threads
2.2.1.3 Handling Multiple Arguments
2.2.1.4 Thread Termination
2.2.1.5 Attributes and Stack Size
2.2.1.6 Example
2.2.2 Threads and C++
2.2.3 Synchronization
2.2.3.1 Mutual Exclusion
2.2.3.2 Beyond Mutual Exclusion
2.2.4 Thread Safety
2.2.5 Deviations
2.2.5.1 Unix Signals
2.2.5.2 POSIX Cancellation
2.3 Conclusions
2.4 Exercises
2.5 References
In computer systems many things must go on at the same time; that is, they must be concurrent. Even in systems with just one processor, execution is generally multiplexed, providing at least the illusion that many things are happening at once. At any particular moment there may be a number of running programs, a disk drive that has completed an operation and requires service, packets that have just arrived from the network and also require service, characters that have been typed at the keyboard, etc. The operating system must divide processor time among the programs and arrange so that they all make progress in their execution. And while all this is going on, it must also handle all the other input/output activities and other events requiring attention as well.
This chapter covers multithreaded programming. The discussion here not only goes through the basics of using concurrency in user-level programs, but also introduces a number of concepts that are important in the operating ...
Get Operating Systems in Depth 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.