Threads
Ch4: Threads
CPIS 222– Principles of Operating Systems -2012– KAU
Dr.Lamiaa Elrefaei
1
Outline
Overview
Multithreading Models
Thread Libraries
Threading Issues
Operating System Examples
Ch4: Threads
CPIS 222– Principles of Operating Systems -2012– KAU
Dr.Lamiaa Elrefaei
2
4.1 Overview
Single-threaded process – multithreaded process:
A thread is a basic unit of CPU utilization.
Traditional process has a single thread of control.
Multithreaded process can perform more than one task at a time.
Many applications are multithreaded.
A web browser might have one thread displaying images while another thread retrieving data from the network.
A word processor may have a thread for responding to keystrokes from the users, and another thread for performing spelling and grammar checking in the background. Many operating system kernels are now multithreaded.
Several threads operate in the kernel.
Each thread performs a specific task.
For example, Linux uses a kernel thread for managing the amount of free memory in the system.
Ch4: Threads
CPIS 222– Principles of Operating Systems -2012– KAU
Dr.Lamiaa Elrefaei
3
4.1 Overview (cont’d)
A thread comprises:
A thread ID.
A program counter.
A register set.
A stack.
It shares with other threads belonging to the same process:
Code section.
Data section.
Other operating-system resources, such as open files.
Ch4: Threads
CPIS 222– Principles of Operating Systems -2012– KAU
Dr.Lamiaa Elrefaei
4
4.1 Overview (cont’d)
Heavyweight Process= process
Ch4: Threads
Lightweight Process = Thread
CPIS 222– Principles of Operating Systems -2012– KAU
Dr.Lamiaa Elrefaei
5
New Process Description Model
Single-threaded process
multithreaded process
Ch4: Threads
CPIS 222– Principles of Operating Systems