Threads vs Processes (Mechanisms used for executing code concurrently)
| Threads(User Space) | Processes | |
|---|---|---|
| What | Lightweight process within a process.(Since no duplication of process space) | Heavy(Complete process space(CS,DS,SS,HS) duplicated) to child |
| Compared |
Fast: No Context Switch(Switching from Thread-1 to Thread-2 does not need context) No memory cache flush, No Trap instruction, Everything is inside process(No need to go in kernel space). Process can decide his own scheduling algo |
Slow: Context Switch needed, Trap needed and to achieve these control need to go into kernel space |
| Disadv | If 1 thread blocks, whole process blocks. |
Why Processes(if they are Heavy wrt Threds?)
2. Security: Processes offer better security because they have separate memory spaces. This helps prevent unintended access or modification of data.
3. Compatibility and Portability: Processes are more portable across different operating systems compared to threads