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

AOS 5 Threads

Uploaded by

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

AOS 5 Threads

Uploaded by

Aroona Noor
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

Introduction To operating Systems

Introduction to Operating Systems

Threads

Department of Computer Sciences,


COMSATS Institute of Information Technology,The Mall
Wah Cantt, Pakistan

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Processes
The Process Model

• Multiprogramming of four programs


• Conceptual model of 4 independent, sequential processes
• Only one program active at any instant

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Process Creation

Principal events that cause process creation


1. System initialization
– Execution of a process creation system
2. User request to create a new process
3. Initiation of a batch job

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Process Termination

Conditions which terminate processes


1. Normal exit (voluntary)
2. Error exit (voluntary)
3. Fatal error (involuntary)
4. Killed by another process (involuntary)

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Thread

• A Light Weight Process

• Threads are a way for a program to split


itself into two or more simultaneously (or
pseudo-simultaneously) running tasks

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Motivation
 Most modern applications are multithreaded
 Threads run within application
 Multiple tasks with the application can be implemented by
separate threads
 Process creation is heavy-weight while thread creation is light-
weight
 Can simplify code, increase efficiency
 Kernels are generally multithreaded

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Multithreading Models

Many-to-One
One-to-One
Many-to-Many

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Many-to-One

• Many user-level threads mapped to


single kernel thread
• One thread blocking causes all to block
• Multiple threads may not run in parallel
on multicore system because only one
may be in kernel at a time
• Few systems currently use this model
• Example:
• Solaris Green Threads

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

One-to-One
• Each user-level thread maps to kernel thread
• Creating a user-level thread creates a kernel thread
• Number of threads per process sometimes restricted due to
overhead
• Examples
• Windows
• Linux
• Solaris 9 and later

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Many-to-Many Model
• Allows many user level threads to be
mapped to many kernel threads
• Allows the operating system to create a
sufficient number of kernel threads
• Examples
– Solaris prior to version 9
– Windows with the Thread Fiber
package

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Two-level Model
• Similar, to M:M, except that it allows a
user thread to be bound to kernel
thread
• Examples
– Tru64 UNIX
– Solaris 8 and earlier

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

TYPES OF THREADS
There are two types of threads

User Level Threads


Kernal Level Threads

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

User-Level Threads
• All thread management is done by the application
• The kernel is not aware of the existence of threads

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Kernel-Level Threads
• W2K, Linux, and OS/2 are examples of this approach
• Kernel maintains context information for the process and
the threads
• Scheduling is done on a thread basis

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Thread Libraries

• Thread library provides programmer with API


for creating and managing threads
• Two primary ways of implementing
• Library entirely in user space
• Kernel-level library supported by
the OS

COMSATS Institute of Information Technology


Wah Cantt Campus
Introduction To operating Systems

Benefits of Threads
 Responsiveness – may allow continued execution if part
of process is blocked, especially important for user
interfaces
 Resource Sharing – threads share resources of
process, easier than shared memory or message
passing
 Economy – cheaper than process creation, thread
switching lower overhead than context switching
 Scalability – process can take advantage of
multiprocessor architectures

COMSATS Institute of Information Technology


Wah Cantt Campus

You might also like