Processes Threads
Processes Threads
Processes
PC
PC PC PC
25
Threads
Models
• Threads of one process (mini-process)
– Describe an sequential execution within a process
– Share the same address space and resources of the process
– Each thread has its own PC, registers and stack of execution
– There is no protection between threads in one process
– Lightweight processes (contains some properties of processes)
– Have its own stack
– Multithreading (multiple threads in same process)
• Having multiple threads running concurrently within a
process is analogous to having multiple processes running
in parallel in one computer
Threads
Model (cont)
Cooperative scheduling
Implementing threads :: Operating systems 2018 (uu.se)
Threads
Implementing Threads in User Space (cont)
Preemptive scheduling
Implementing threads :: Operating systems 2018 (uu.se)
Threads
Implementing Threads in the Kernel
• The kernel knows about the threads and manage the
threads (no run-time system is needed)
• The kernel schedules all the threads
• The kernel has a thread table (using kernel call to create
or destroy thread)
• Advantages
– The kernel can switch between threads belonging to different
processes
– No problem with blocking system calls
– Useful if multiprocessor support is available (multiple CPUs)
• Disadvantages
– Greater cost (time and resources to manage threads create and
terminate) → Solution: recycling
– Thread creation, saving is slow (needs system call)
Threads
Implementing Threads in the Kernel (cont)
Operating System - M
ulti-Threading (tutorial
spoint.com)
Summary
• Processes
• Threads
Q&A
Next Lecture
• Threads Implementation
• InterProcess Communication