You are on page 1of 12

THREADS INTRODUCTION

(OPERATING SYSTEMS)

By: SAIQA ASGHAR

Friday, November 3,
1
2017
CONTENT

Thread
Multithreading
Process vs. Thread
Advantages of multithreading
Disadvantages

Friday, November 3,
2
2017
THREAD

A thread of execution is the smallest sequence of


programmed instructions that can be managed
independently by a scheduler.

It is also called lightweight process.


A thread is a basic unit of CPU utilization, consisting of a
program counter, a stack, and a set of registers, ( and a
thread ID. )

Friday, November 3,
3
2017
Friday, November 3,
4
2017
Multi-threading

A multi-threaded process means more than one part of the


same process may be running at one time.
In multi-threaded task, one thread may be blocked and
waiting for something while another thread in the same
task may be running.
Multi threading is useful in programs such as web
browsers where you may wish to download a file, view an
animation and print something at the same time.

Friday, November 3,
5
2017
Why Multithreading?

The idea is 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, other thread to process inputs etc.

Friday, November 3,
6
2017
A thread shares some things ( Code section, Data section, operating
system resources with its peers.

Friday, November 3,
7
2017
PROCESS vs THREAD

1. A process is a heavy weight 1. A thread is a lightweight entity.


entity.
2. A thread cannot exist without a
2. There must be at least one process.
thread in the process.
3. A thread has no data segment
3. A process has code, data and or heap.
heap segment.
4. If a thread ends, the process
4. If a process ends, all the may still run.
threads in it also end.
5. The communication among
5. The communication among threads occurs via memory.
processes occurs via operating
systems.

Friday, November 3,
8
2017
ADVANTAGES OF MULTI THREADING
Responsiveness: If the process is divided into multiple
threads, if one thread completed its execution, then its
output can be immediately responded while other thread is
busy in lengthy calculations. For example a browser allows
a user to interact with it while a file is being downloaded.
Resource sharing: Resources like memory, code, data and
file can be shared among all threads within a process.
stack and registers cant be shared among the threads. Each thread
have its own stack and registers.

Effective Utilization of Multiprocessor system: If we have


multiple threads in a single process, then we can schedule
multiple threads on multiple processor. This will make
process execution faster.
Friday, November 3,
9
2017
ADVANTAGES

Communication: Communication between multiple thread


is easier as thread shares common address space. while in
process we have to follow some specific communication
technique for communication between two process.
Economy: allocation of memory and resources for process
creation is costly. All threads of a process share the
resources of that process so it is more economical to create
and context switch.

Friday, November 3,
10
2017
DISADVANTAGES

Blocking:
The major disadvantage if that if the kernel is single threaded,
a system call of one thread will block the whole process and CPU
may be idle during the blocking period.

Security:
Since there is, an extensive sharing among threads there is a
potential problem of security.

Friday, November 3,
11
2017
ADDITIONAL INFORMATION

a code segment, also known as a text segment or simply


as text, is a portion of an object file or the corresponding
section of the program's virtual address space that contains
executable instructions.
virtual address space (VAS) or address space is the set
of ranges of virtual addresses that an operating
system makes available to a process

Friday, November 3,
12
2017

You might also like