Thread Vs Processes in Distributed Systems
Thread Vs Processes in Distributed Systems
Distributed Systems
Processes, Threads, Code Migration
Process
What is a Thread?
• Execution context
– Program counter (PC) Stack (T1)
SP (T1)
– Stack pointer (SP) Stack (T2)
– Data registers SP (T2)
Heap
Static Data
PC (T1)
PC (T2) Code
Process
Process vs. Thread (1)
• Process: unit of allocation
– Resources, privileges, etc
• Thread: unit of execution
– PC, SP, registers
• Each process has one or more threads
• Each thread belong to one process
Process vs. Thread (2)
• Processes
– Inter-process communication is expensive: need to
context switch
– Secure: one process cannot corrupt another process
Process vs. Thread (3)
• Threads
– Inter-thread communication cheap: can use process
memory and may not need to context switch
– Not secure: a thread can write the memory used by
another thread
User Level vs. Kernel Level Threads
• User level: use user-level thread package; totally
transparent to OS
– Light-weight
– If a thread blocks, all threads in the process block
• Kernel level: threads are scheduled by OS
– A thread blocking won’t affect other threads in the same
process
– Can take advantage of multi-processors
– Still requires context switch, but cheaper than process
context switching
Thread Implementation
• Combining kernel-level lightweight processes and user-level threads
– LWPs are transparent to applications
– A thread package can be shared by multiple LWPs
– A LWP looks constantly after runnable threads
User-level, Kernel-level and Combined