Abstract
- Responsible to carry out some features of a Process (进程)
- Threads in a process share the same Address Space & other per-process items as shown below
- There are 3 types - User Thread, Kernel Thread & Hybrid Thread
More Performant
Since thread doesn’t have the need to perform Expensive Context Switching. It is 10-100 times faster than Process.
Faster to create and destroy compared to process, because it can be created without making System Call (系统调用) to the underlying Kernel.
Easier to program
Unlike process, different parts of program able to communicate without the use of Interrupts (中断) and Inter-Process Communication (IPC) etc.
No protection among threads
One thread can read, write, or even wipe out another thread’s stack. It is also able to bring down the entire Process.
Forking
Should we copy over all the threads or just a single one?
Interrupt Handling
For Software Interrupt handling - which thread should handle it?
Blocking Thread
- Known as Synchronised Thread
- Thread doesn’t do anything while waiting for IO Operations or Network Operations etc
- Super-simple to use and understand!
Thread Table
- To keep track of the Thread in a Process (进程)
- Similar to Kernel’s Process Table, except it only keeps track of the per-thread items
- Managed by the Runtime System for User Thread & Kernel for Kernel Thread
PThread
pthread_yield()
In Process (进程), we don’t have this. Because Thread is in the same program, written by the same programmer, so they collaborate to get fulfil a particular feature