Professional Documents
Culture Documents
SUSHMA RAWAL
THREAD
A thread of execution is the smallest unit
of processing that can be scheduled by an
operating system.
OR
A thread is the basic unit of CPU
utilization.
SUSHMA RAWAL
THREAD
A thread is the primitive that can execute code
A thread is a single sequential flow of control within a
process
A process can have many threads of execution
Different threads, which are part of a process, share the
same address space; meaning they share the data memory,
code memory and heap memory area
Threads maintain their own thread status (CPU register
values), Program Counter (PC) and stack
SUSHMA RAWAL
Threads
Threads are called light weight processes.
Processes are called heavy weight
processes.
SUSHMA RAWAL
Threads
Examples
A web browser
A word processor
A web server
SUSHMA RAWAL
SUSHMA RAWAL
Benefits of multithreading
Responsiveness
Resource Sharing
Economy
Utilization of Multiprocessor Architectures
SUSHMA RAWAL
SUSHMA RAWAL
SUSHMA RAWAL
10
SUSHMA RAWAL
11
Why Threads?
SUSHMA RAWAL
12
Threads
SUSHMA RAWAL
13
Threads
Context switching is fast when working with
threads. The reason is that we only have to save
and/or restore PC, SP and registers.
SUSHMA RAWAL
14
Threads
Threads are of two types
User level threads
Kernel level threads
SUSHMA RAWAL
15
Threads
User Level Thread:
User level threads do not have kernel/Operating System
support and they exist solely in the running process.
Even if a process contains multiple user level threads, the
OS treats it as single thread and will not switch the
execution among the different threads of it.
It is the responsibility of the process to schedule each
thread as and when required.
In summary, user level threads of a process are nonpreemptive at thread level from OS perspective.
SUSHMA RAWAL
16
User-Level Threads
User-level threads implement in user-level libraries, rather
than via systems calls, so thread switching does not need to
call operating system and to cause interrupt to the kernel.
Examples
- POSIX Pthreads
- Mach C-threads
- Solaris threads
SUSHMA RAWAL
17
User-Level Threads
Advantages:
Simple Representation:
Each thread is represented simply by a PC,
registers, stack and a small control block, all
stored in the user process address space.
Simple Management:
This simply means that creating a thread,
switching between threads and synchronization
between threads can all be done without
intervention of the kernel.
SUSHMA RAWAL
18
User-Level Threads
Fast and Efficient:
Thread switching is not much more expensive
than a procedure call.
SUSHMA RAWAL
19
User-Level Threads
Disadvantages:
SUSHMA RAWAL
20
User-Level Threads
SUSHMA RAWAL
21
Kernel-Level Threads
In this method, the kernel knows about threads
and manages them.
Instead of thread table in each process, the kernel
has a thread table that keeps track of all threads in
the system.
In addition, the kernel also maintains the
traditional process table to keep track of processes.
Operating Systems kernel provides system call to
create and manage threads.
SUSHMA RAWAL
22
Kernel-Level Threads
Advantages:
Because kernel has full knowledge of all threads,
Scheduler may decide to give more time to a
process having large number of threads than
process having small number of threads.
Kernel-level threads are especially good for
applications that frequently block.
SUSHMA RAWAL
23
Kernel-Level Threads
Disadvantages:
The kernel-level threads are slow and inefficient.
For instance, threads operations are hundreds of
times slower than that of user-level threads.
Since kernel must manage and schedule threads as
well as processes. It require a full thread control
block (TCB) for each thread to maintain
information about threads. As a result there is
significant overhead and increase in kernel
complexity.
SUSHMA RAWAL
24
Kernel-Level Threads
Examples
- Windows 95/98/NT/2000
- Solaris
- Linux
SUSHMA RAWAL
25
26
27
SUSHMA RAWAL
28
SUSHMA RAWAL
29
30
SUSHMA RAWAL
31
32