Multitasking is a key feature in almost all operating systems; it increases the efficiency of the CPU and utilizes resources in a better manner. Threads are the best way to implement multitasking. A process can contain more than one thread to implement multitasking.
In this chapter, we will cover the following recipes involving threads:
- Performing a task with a single thread
- Performing multiple tasks with multiple threads
- Using mutex to share data between two threads
- Understanding how a deadlock is created
- Avoiding a deadlock
The terms process and thread can be confusing, so first, we'll make sure that you understand them.