13 Operating_System_Lec_13_Multi-Tthreading
13 Operating_System_Lec_13_Multi-Tthreading
This section describes thread, types of threads and various thread models.
What is Thread?
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 processes.
Difference between Process and Thread
Process is heavy weight or resource Thread is light weight taking lesser resources
1
intensive. than a process.
Process switching needs interaction with Thread switching does not need to interact
1
operating system. with operating system.
Multiple processes without using threads Multiple threaded processes use fewer
1
use more resources. resources.
In multiple processes each process One thread can read, write or change another
1
operates independently of the others. thread's data.
Advantages of Thread
Thread minimizes context switching time.
Efficient communication.
Advantages
Thread switching does not require Kernel mode privileges.
Disadvantages
In a typical operating system, most system calls are blocking.
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.
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
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.
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 support 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.
Difference between User Level & Kernel Level
Thread
User level threads are faster to create Kernel level threads are slower to create and
1
and manage. manage.
User level thread is generic and can run Kernel level thread is specific to the operating
3
on any operating system. system.