0% found this document useful (0 votes)
2 views29 pages

Module 1 Threads Part 2 (1)

The document discusses threads as lightweight processes that enhance application performance through parallelism, with each thread belonging to a single process. It outlines the advantages and disadvantages of user-level and kernel-level threads, as well as various multithreading models and multicore systems. Additionally, it covers CPU scheduling criteria such as CPU utilization, throughput, turnaround time, waiting time, and response time to optimize performance.

Uploaded by

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

Module 1 Threads Part 2 (1)

The document discusses threads as lightweight processes that enhance application performance through parallelism, with each thread belonging to a single process. It outlines the advantages and disadvantages of user-level and kernel-level threads, as well as various multithreading models and multicore systems. Additionally, it covers CPU scheduling criteria such as CPU utilization, throughput, turnaround time, waiting time, and response time to optimize performance.

Uploaded by

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

THREADS

 A thread is a flow of execution through the process code, with its


own program counter, system registers and stack.
A thread is also called a light weight process.
Threads provide a way to improve application performance through
parallelism.
Threads represent a software approach to improving performance of
operating system by reducing the overhead thread is equivalent to a
classical process.
• Each thread belongs to exactly one process and no thread can exist outside

a process.

• Each thread represents a separate flow of control.

• Threads have been successfully used in implementing network servers and

web server.

• They also provide a suitable foundation for parallel execution of

applications on shared memory multiprocessors.

• Following figure shows the working of the single and multithreaded


3
processes.
Advantages of Thread :

Thread minimizes context switching time.

Use of threads provides concurrency within a process.

Efficient communication.

Economy- It is more economical to create and context

switch threads.
Utilization of multiprocessor architectures to a greater

scale and efficiency.


Types of Thread:
Threads are implemented in following two ways

User Level Threads - User managed threads

Kernel Level Threads - Operating System

managed threads acting on kernel, an operating


system core.
User Level Threads :

• In this case, application manages thread management

kernel is not aware of the existence of threads.


• The thread library contains code for creating and

destroying threads, for passing message and data


between threads, for scheduling thread execution and
for saving and restoring thread contexts.
• The application begins with a single thread and begins

running in that thread.


Advantages :
Thread switching does not require Kernel mode

privileges.
 User level thread can run on any operating system.

Scheduling can be application specific in the user

level thread.
User level threads are fast to create and manage.
Disadvantages
In a typical operating system, most system calls are

blocking.

Multithreaded application cannot take advantage of

multiprocessing
 Kernel Level Threads
o In this case, thread management done by the Kernel.

o There is no thread management code in the application

area.
o Kernel threads are supported directly by the operating

system.
o Any application can be programmed to be multithreaded.

o All of the threads within an application are supported

within a single process.


The Kernel maintains context information for the

process as a whole and for individuals’ threads


within the process.
Scheduling by the Kernel is done on a thread basis.

The Kernel performs thread creation, scheduling

and management in Kernel space.


Kernel threads are generally slower to create and

manage than the user threads.


Advantages
Kernel can simultaneously schedule multiple

threads from the same process on multiple


processes.
If one thread in a process is blocked, the Kernel

can schedule another thread of the same process.


 Kernel routines themselves can multithreaded.
 Disadvantages

 Kernel threads are generally slower to create and manage than the

user threads.
 Transfer of control from one thread to another within same process

requires a mode switch to the Kernel.

 Multithreading Models
Some operating system provides a combined user level

thread and Kernel level thread facility.


Solaris is a good example of this combined approach.
 In a combined system, multiple threads within
the same application can run in parallel on multiple
processors and a blocking system call need not
block the entire process.
Multithreading models are three types

 Many to many model

 Many to one model

 One to one model


Many to Many Model
In this model, many user level threads multiplexes to the

Kernel thread of smaller or equal numbers.


The number of Kernel threads may be specific to either a

particular application or a particular machine.


Following diagram shows the many to many model.

In this model, developers can create as many user threads

as necessary and the corresponding Kernel threads can run


in parallels on a multiprocessor.
Many to one model
• Many to one model maps many user level threads to one

Kernel level thread.


• Thread management is done in user space.

• When thread makes a blocking system call, the entire

process will be blocks.


• Only one thread can access the Kernel at a time, so

multiple threads are unable to run in parallel on


multiprocessors.
• If the user level thread libraries are implemented in the operating

system in such a way that system does not support them then Kernel
threads use the many to one relationship modes.
One to one model
• There is one to one relationship of user level thread to the

kernel level thread.


This model provides more concurrency than the many to
one model.
It also another thread to run when a thread makes a
blocking system call.
It supports multiple thread to execute in parallel on
microprocessors.
Disadvantage of this model is that creating user thread

requires the corresponding Kernel thread.


 OS/2, Windows NT and windows 2000 use one to one

relationship model.
 Multicore System
 A single computing component with multiple cores (Independent

processing units) is known as multicore processor


 It denotes the presence of a single CPU with several cores in the

system.
 Individually, these cores may read and run computer instructions.

 A single processor in a multicore system my run many instructions

simultaneously.
 It will increase the overall speed of the system’s program execution
 Advantages
• Multicore processors may execute more data than single-

core processors

• It will have less traffic

• These systems are energy efficient , because they provide

increased performance while using less energy

• The PCB ( process control block) requires less space


 Disadvantages

• It is very difficult to manage than single-core

processors
• These systems are use huge electricity

• Much expensive than single-core processors

• It will run slightly slower than single-core

processors
CPU scheduling criteria
 Many criteria have been suggested for comparing CPU scheduling

algorithms.
 Which characteristics are used for comparison can make a

substantial difference in which algorithm is judged to be best.


 The criteria include the following:

 CPU Utilization - We want to keep the CPU as busy as possible.

Conceptually, CPU utilization can range from 0 to 100 percent.


 In a real system, it should range from 40 percent (for a lightly loaded

system) to 90 percent (for a heavily used system).


Throughput - If the CPU is busy executing processes, then work is being
done.
• One measure of work is the number of processes that are completed per

time unit, called throughput.


• For long processes, this rate may be one process per hour; for short

transactions, it may be 10 processes per second.

Turnaround time - From the point of view of a particular process, the


important criterion is how long it takes to execute that process.
• The interval from the time of submission of a process to the time of

completion is the turnaround time.


• Turnaround time is the sum of the periods spent waiting to get into
memory, waiting in the ready queue, executing on the CPU, and doing I/O.
Waiting time - The CPU scheduling algorithm does not
affect the amount of time during which a process executes or
does I/O;
• It affects only the amount of time that a process spends

waiting in the ready queue.


• Waiting time is the sum of the periods spent waiting in the

ready queue.
Response time - In an interactive system, turnaround time may
not be the best criterion.
• Often, a process can produce some output fairly early and can
continue computing new results while previous results are being
output to the user.
• Thus, another measure is the time from the submission of a request

until the first response is produced.


• This measure, called response time, is the time it takes to start

responding, not the time it takes to output the response.


• The turnaround time is generally limited by the speed of the output

device.
• It is desirable to maximize CPU utilization and throughput

and to minimize turnaround time, waiting time, and


response time.
• In most cases, we optimize the average measure.

• However, under some circumstances, it is desirable to

optimize the minimum or maximum values rather than the


average.
• For example, to guarantee that all users get good service,

we may want to minimize the maximum response time

You might also like