Multithreading #
A variety of programming languages (like Java) allow associating a computational task to a thread, and executing several threads in parallel (on different cores) or concurrently (on the same core, in an interleaved fashion).
A consequence is that the precise order in which threads execute their respective operations can be unpredictable.
When threads need to communicate, this can result in a program whose behavior is difficult to understand. Notably, bugs that involve multithreading may not be consistently reproducible (even on the same hardware).
In this chapter, we give a very brief (and simplified) overview of multithreading as a programming tool, and how to use it in Java.
This includes basic mechanisms (such as mutual exclusion or condition variables) to impose constraints on the order of execution of certain instructions, when several threads are running in parallel and/or concurrently.
We also present some higher-level utilities that allow taking advantage of multithreading in a less error-prone fashion.