0% found this document useful (0 votes)
19 views

Threads

The document discusses threads in operating systems. It introduces threads and their benefits, describes different threading models like one-to-one, many-to-one and many-to-many, and explains how threads allow parallel execution and improve responsiveness of applications.

Uploaded by

cigila6437
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Threads

The document discusses threads in operating systems. It introduces threads and their benefits, describes different threading models like one-to-one, many-to-one and many-to-many, and explains how threads allow parallel execution and improve responsiveness of applications.

Uploaded by

cigila6437
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

THREADS

THREADS Operating Systems 1


Roadmap
• Introduction
• Multicore Programming
• Multithreading Models
• Benefits of Threads
• Thread Libraries

Operating Systems Threads 2


Scenario

• Lets assume, a program is not capable of drawing


pictures while reading keystrokes. The program must
give its full attention to the keyboard input lacking the
ability to handle more than one event at a time.
• The ideal solution to this problem is the seamless
execution of two or more sections of a program at the
same time. Threads allows us to do this.

Operating Systems Threads 3


Introduction

• A thread is a basic unit of CPU utilization;

Thread = Thread ID + Program counter + Register set + stack.


• It shares with other threads belonging to the same
process its code section, data section, and other
operating-system resources, such as open files and
signals.

Operating Systems Threads 4


Processes and Threads
Multithreading: More than one entities can possibly execute in the same
resource- (i.e., process-) environment (and collaborate better)

Operating Systems Threads 5 5


Single and Multithreaded
Processes

Operating Systems Threads 6


Multithreading
• Most software applications that run on modern
computers are multithreaded.
• An application typically is implemented as a separate
process with several threads of control.
 A web browser might have one thread display images or text while
another thread retrieves data from the network
 A word processor may have a thread for displaying graphics, another
thread for responding to keystrokes from the user, and a third thread for
performing spelling and grammar checking in the background.
Finally, most operating-system kernels are now multithreaded.
Several threads operate in the kernel, and each thread performs
a specific task, such as managing devices, managing memory, or
interrupt handling.
Operating Systems Threads 7
Multithreaded Server Architecture – Example

Parallel execution on single core and multicore

Operating Systems 4-Threads


Threads 8 10
Multithreading Models
Support for threads may be
provided either at:

 User level: User threads


 Kernel level: Kernel Threads

• A relationship must exist


between user and kernel threads.
Three common models are:
 the one-to-one model
 the many-to-one model
 the many-to-many model

Operating Systems Threads 9


Many-to-One Model

Operating Systems Threads 10


Multithreading Models

One-to-One model

• The one-to-one model maps each user thread to a kernel


thread. It also allows multiple threads to run in parallel
on multiprocessors.
Operating Systems Threads 11
Multithreading Models

One-to-One model
• The only drawback to this model is that creating a user
thread requires creating the corresponding kernel thread.
Because the overhead of creating kernel threads can
burden the performance of an application, most
implementations of this model restrict the number of
threads supported by the system.

Operating Systems Threads 12


Multithreading Models

Many-to-Many model
• Allows many user level threads to be mapped to many
kernel threads.

• Allows the operating system to


create sufficient number of kernel threads.

Operating Systems Threads 13


Many-to-Many Model

Operating Systems Threads 14


Benefits of Threads
• Easy/Lightweight Communication
– Threads within the same process share memory and files
– Communication does not invoke the kernel

• May allow parallelization within a process


– I/O and computation to overlap
 Recall historical evolution from uni-programming to multiprogramming
– Concurrent execution in multiprocessors

• Takes less time to


– Create/terminate a thread than a process
– Switch between two threads within the same process

1
5
Benefits

• Responsiveness

• Resource Sharing

• Economy

• Scalability

Operating Systems Threads 16

You might also like