0% found this document useful (0 votes)
46 views24 pages

Threads

This document discusses threads and multithreading models. It defines a thread as the basic unit of CPU utilization that shares code, data, and system resources with other threads in a process. There are three common multithreading models: many-to-one maps multiple user threads to a single kernel thread; one-to-one maps each user thread to a kernel thread; many-to-many maps some number of user threads to some number of kernel threads. Multithreading provides benefits like increased responsiveness, resource sharing, lower costs compared to processes, and better utilization of multiprocessor systems.

Uploaded by

Ajay Kumar R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views24 pages

Threads

This document discusses threads and multithreading models. It defines a thread as the basic unit of CPU utilization that shares code, data, and system resources with other threads in a process. There are three common multithreading models: many-to-one maps multiple user threads to a single kernel thread; one-to-one maps each user thread to a kernel thread; many-to-many maps some number of user threads to some number of kernel threads. Multithreading provides benefits like increased responsiveness, resource sharing, lower costs compared to processes, and better utilization of multiprocessor systems.

Uploaded by

Ajay Kumar R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

CONTENTS:-

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

Registers Registers Registers


Registers stack

Stack Stack Stack

Thread

Threads

SINGLE-AND MULTITHREADED PROCESSES


User threads :-
These are implemented by a
thread library at the user level. The library
provides support for thread creation,
scheduling and management with no support
from the kernel. Because, the kernel is
unaware of user-level threads, all thread
creation and scheduling. Therefore ,user-level
threads are generally fast to create and
manage.
User-thread libraries include POSIX,
P-threads and Solaris 2 UI-threads.
Kernel threads:-
These are supported directly by
the OS. The kernel performs thread creation,
scheduling and management in kernel
Space. Kernel thread is the “lightest” unit of
Kernel scheduling. Kernel threads are generally
slower to create and manage than the user
threads.
If a thread performs blocking system call,
the Kernel can schedule another thread in the
application for execution,
example:- Solaris 2,True 64 Unix(formerly
digital UNIX).
PROCESS:-
A process is the “heaviest” unit of
kernel scheduling. Processes has its own
resources allocated by the operating system.
Resources include memory ,file handles ,
device handles and windows.
Process are typically pre-emptively
multitasking.
Differences between process and thread.
Process are typically
independent, while threads exit as a
subset of a process.
Process carry its own state of
information, but threads within a
process shares state as well as memory.
Process have separate address
spaces, where threads shares their same
address space
Multi-threading models:-
Many system provide
support for user and kernel threads,
resulting in different multithreading
models.
The three common types of
thread implementation are-
1) Many-to-one –Model
2) One-to-one – Model
3) Many-to-Many-Model
Many-to-one –model;-
This model can also be represented
as N:1 Model. It implies that all application
Level threads map on to a single Kernel-
level scheduler entity.

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

One-to one model


Drawback:-
1).Creating a user thread requires
corresponding Kernel thread.
Because,overhead of creating Kernel thread
can burden the performance of an application.
2).This model restrict the number of threads
supported by the system.
Advantages:-
1).This model allows multiple
threads to run in parallel on multiprocessors.
2).This is the simplest possible threading
implementation.
Many-to-Many model:-
It can also be represented as N:M model.
It maps some N number of application threads to
some M number of kernel threads. The user level
threads are smaller or equal Number of kernel
threads.
User 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.

You might also like