Threads
Threads
INTRODUCTION
DEFINITION-USER THREAD
KERNEL THREAD &PROCESS
MULTI-THREADING MODEL-
ONE-TO-ONE MODEL
ONE-TO-MANY MODEL
MANY-TO-MANY MODEL
ADVANTAGES OF MULTITHREADING MODEL
INTRODUTION:-
A thread of execution is a
fork of computer program in to two or more
concurrently running tasks. The
implementation of threads and its process
differs from one operating system to
another,but in most of the cases,a thread is
contained inside a process can exist with in
the same process and share resources such as
memory.
In a multiprocessor system , the threads
are generally run at the same time, with
each processor running a particular thread .
Support for threads in programming
language varies. The languages which use
threads are called user threads ,in which
threads not visible to the Kernel, by this it
cannot be scheduled to run concurrently.
On the other hand, another type of thread
called Kernel threads , in which threads are
visible to the kernel, it will indeed enable
true concurrency.
DEFINITION:-
A thread is also called a Light
Weighted Process(LWP) that shares the
same time and information.
And also, it is a basic unit of CPU
Utilization. It comprises a thread ID, a
program counter ,a register set and a stack.
A thread shares with other threads
belonging to the same process,
example:-code section, data section shares
the other operating system such as open
files and signals.
Code Data Files Code Data Files
Thread
Threads
User thread
K Kernel thread
In Many-to One model many user level threads
maps to one kernel thread.
Drawback:-
1)The entire process will block if a thread makes
a blocking system call.
2)Only one thread can access the kernel at a
time, multiple threads are unable to run in
parallel on a multi-process basis.
3)It cannot benefit from the hardware
acceleration on multi-threaded process.
Advantages:-
1).Context switching can be done
very fast.
2).It can be implemented even on simple
kernel which do not support for threading.
3).Thread management is done in user space,
so it is efficient.
Green threads- a thread library
available for Solaries2- uses this model
One-to-one-model:-
This model can also be
represented by 1:1.Here,1:1 threads created
by the user are in 1-1 correspondance with
schedulable entities in the kernel.
In this model maps each user
thread to a kernel thread.
Windows NT,Windows 2000 and
OS/2 are implemented by 1-1 model
User thread
K K K K
Kernel thread
Kernel thread
k K K
Drawback:-
1)N:M threading system are more
complex to implement than either Kernel or
user thread. Because, for any changes kernel
and user-thread code are required.
2)It increases the complexity of priority
inversely without extensive coordination
between the user scheduler and kernel thread.
Advantages:-
1)This makes context switching of
threads
Very fast.
Thread cancellation:-
Terminating a thread before it has completed
called “thread cancellation”.
A thread that has to be cancelled called
“target thread”.
Cancellation of a target may occur in two
ways:-
1).Asynchronous cancellation:-One thread can
immediately terminates the target thread.
2).Deferred cancellation:-The target thread can
periodically check if it should terminate,
allowing the target thread to terminate itself in
Advantages of multithreaded programming:-
It can be divided in to four major categories.
1).Responsiveness:- It allow a program to
continue running even if part of it is blocked or
performing lengthy operation.
2).Resource sharing:-Thread share the memory
and resources of the process to which they
belong.
3).Economy:-Allocating memory and resources
for process creation is costly. It is more
economical to create and context switch thread.
4).Utilization of multiprocessor architectures:-
It greatly increases the multiprocessor
architecture. Multithreading on a multi-CPU
machine increases concurrency. Because, in a
single-processor architecture, CPU generally
moves between each thread, where as in multi-
processor each thread can run parallel on a
different processor.
Conclusion:-
Threads are play a vital role in
remote procedure call(RPC) system. It will
allows program to operate faster. The POSIX
threads library provides application to create
and control additional threads for execution.
The challenges of threads are many. This
increases the program complexity and the
difficulty of debugging and optimising the
application.