Operating System Threads-Updated
Operating System Threads-Updated
Thread Overview
• Threads are mechanisms that permit an application to perform
multiple tasks concurrently
• Thread is a basic unit of CPU utilization
– Thread ID
– Program counter
– Register set
– Stack
• A single program can contain multiple threads
– Threads share with other threads belonging to the same
process
• Code, data, and other resources such as open files and
signals
Process Vs Thread
Pro Thread
cess
2 Process switching needs interaction with Thread switching does not need to interact
operating system. with operating system.
3 In multiple processing environments, All threads can share same set of open files,
each process executes the same code but child processes.
has its own memory and file resources.
4 If one process is blocked, then no other While one thread is blocked and waiting, a
process can execute until the first process second thread in the same task can run.
is unblocked.
5 Multiple processes without using threads Multiple threaded processes use fewer
use more resources. resources.
6 In multiple processes each process One thread can read, write or change
operates independently of the others. another thread's data.
Single and Multithreaded Processes
Traditional
(heavyweight)
process has a
single thread
of control
• Sharing of Resources
All threads share the resources allocated to their owner process
• No need of IPC
Threads do not required system call to communicate with each
other. As they share code and data section of process.
A thread table is maintained for user threads. The thread table has
the entries to point the TCB of each thread.
User threads
Creating and managing the user threads is easy and much faster
as compared to a process and a kernel thread.
User threads are more portable also due to their nature as they
do not require the support from kernel making them independent
of a particular operating system.
The user process requests a kernel thread using a system call and
in turn the OS creates a kernel thread that executes user thread’s
instruction
Kernel threads
Kernel Threads
• Supported directly by the operating system
• Kernel performs creation, scheduling and management in
kernel space
• Generally slower to create and manage than are user threads
• Examples
– Windows XP/2000
– Solaris
– Linux
– Tru64 UNIX
– Mac OS X
Hybrid threads
Multithreading Models
User Thread – to - Kernel Thread
• Many-to-One
• One-to-One
• Many-to-Many
Many-to-One
User thread are implemented by users. kernel threads are implemented by OS.
OS doesn’t recognized user level threads. Kernel threads are recognized by OS.