Understanding multithreading in Python and its limitations
A thread is a basic unit of execution within an operating system process, and it consists of its own program counter, a stack, and a set of registers. An application process can be built using multiple threads that can run simultaneously and share the same memory.
For multithreading in a program, all the threads of a process share common code and other resources, such as data and system files. For each thread, all its related information is stored as a data structure inside the operating system kernel, and this data structure is called the Thread Control Block (TCB). The TCB has the following main components:
- Program Counter (PC): This is used to track the execution flow of the program.
- System Registers (REG): These registers are used to hold variable data.
- Stack: The stack is an array of registers that manages the execution history.
The anatomy of a thread is exhibited in Figure 7.1, with three threads...