Académique Documents
Professionnel Documents
Culture Documents
AUTHOR: SILBERCHATZ ,
GALVIN AND
GAGNE
PRESENTED
BY: HEENAZ
Topics covered:
Threads
Difference
processes
Types of processes with threads
Benefits of multithreaded
programming
User and kernel threads
Threading implementations
Threading Issues
Threads:
Relatively
recent development in
OS.
Light weight process which is a
basic unit of CPU utilization.
Process with single thread is
called as classical process.
Each thread is associated with a
single process ( sequential flow of
control ).
Takes over the role of process as
processes:
Processes are typically
independent, while threads exist
as subsets of a process.
Processes carry considerably
moreinformation than threads,
whereas multiple threads within a
process share memory as well as
otherresources.
Processes have separateaddress
space, whereas threads share
their address space.
registers
data
files
stack
Thread
Multithreaded
process:
hread may
display image while other thread may retrieve th
a network.
code
registe
rs
stac
k
data
register
stack
files
register
stack
Thread
Benefits of multithreaded
programming:
Many-to-one Model
One-to-one Model
It maps each user thread to kernel thread.
If a thread makes a blocking system call, then it allows
the other thread to run parallely.
Drawback: Creating a user thread requires creating
the corresponding Kernel thread.
Many-to-many Model
It maps many user level threads to smaller or equal
Kernel threads.
We can create as many user threads as necessary and
the corresponding Kernel threads run in parallel on
multiprocessor.
Threading Issues:
1.Fork system call
2.Cancellation
3.Signal Handling
4.Thread Pools
sed after the fork system call by one of the two proc
to replace the process memory space.
Cancellation:
It is the task of terminating a thread before it has
completed.
Eg. If multiple threads are searching through the
data base and one thread returns the result, the
remaining threads might be cancelled.
The thread which is to be cancelled is known as
target thread.
Two scenarios:
1)Asynchronous cancellation: One thread
immediately terminates the target thread.
2) Defered cancellation: Allowing the target
Signal Handling:
It is used to notify a process that a particular event
has occured.
The signal may occur synchronously or
asynchronously.
All signals follow the folowing pattern:
A signal is generated by the occurence of the
particular event.
A generated
signal is delivered to a process.
Thread
Pools:
Once delivered, the signal must be handled.
The idea is to create the threads at process startup
and place them into a pool.
When a request is received, the thread becomes active
and completes its service.
Java
Threads:
Threads
are managed by Java Virtual
Machine.
Difficult to classify whether the thread
belongs to user level or Kernel level.
Each process has its own thread.
Even a simple java program consisting of only
a main method runs as a single thread in the
JVM.
Thread Creation:
One way to create a thread explicitly is to create a new
class that is derived from the Thread class, and to
override the run method of the Thread class .
Calling the start method for the new object does two
things:
1. It allocates memory and initializes a new thread in
the JVM.
2. It calls the run method, making the thread eligible to
be run by the JVM.
When the summation program runs, two threads are
created by the JVM. The first is the thread associated
with the application-the thread that starts execution
at the main method. The second thread is the
summation thread that is created explicitly with the
u
o
y
k
n
a
h
T