Unit 3 Threads
Unit 3 Threads
Unit 3 Threads
What is a Thread?
A thread is a path of execution within a
process. A process can contain multiple
threads.
A thread is also known as lightweight
process.
The idea is to achieve parallelism by dividing
a process into multiple threads.
For example, in a browser, multiple tabs can
be different threads. MS Word uses multiple
threads: one thread to format the text,
another thread to process inputs, etc.
Thread is an execution unit which consists of its own
program counter, a stack, and a set of registers.
Program counter keeps track of which instruction to
execute next, system registers which hold its current
working variables, and a stack which contains the
execution history.
Multithreading
A thread is a path which is followed during a
program’s execution.
Lets say, for example a program is not
capable of reading keystrokes while making
drawings. These tasks cannot be executed by
the program at the same time. This problem
can be solved through multitasking so that
two or more tasks can be executed
simultaneously.
Multitasking is of two types: Processor based and thread
based.
Processor based multitasking is totally managed by the
OS, however multitasking through multithreading can be
controlled by the programmer to some extent.
The concept of multi-threading needs proper
understanding of these two terms – a process and a
thread.
A process is a program being executed. A process can be
further divided into independent units known as threads.
A thread is like a small light-weight process within a
process Or we can say a collection of threads is what is
known as a process.
Process vs Thread?
The process has its own Process Thread has Parents’ PCB, its own
Control Block, Stack, and Address Thread Control Block, and Stack and
Space. common Address space.
in their programs.
Kernel Level Threads −
Operating System managed threads acting on kernel.
Kernel threads are supported within the kernel of the
Example
For example
Consider P1, P2 with time period 50,100 resp. and B.T
20,35 resp.
Cal. CPU utilization of each process and total CPU
utilization.
Sol:
CPU utilization=(Burst time/Time period)= (Ti/Pi)
For P1: (20/50)=0.40 i.e 40%
For P2: (35/100)=0.35 i.e 35%
Total CPU utilization is 75%
Earliest Deadline First Scheduling
The earlier the deadline, the higher the priority the later
the
deadline, the lower the priority.