You are on page 1of 11

Operating Systems

Course Code: MCC510


Threads:
➢ It is a basic unit of CPU utilization which comprises a thread ID, a program
counter, a register set and a stack. It shares with other threads belonging to the
same process its code section and other OS resources such as open files and
signals.
➢ Threads are popular way to improve application performance through
parallelism. A thread is sometimes known as light weight process.
➢ Single threaded process- It has a single thread of control. MS DOS support
single user process and a single thread
➢ Multi threaded Process-It has multiple thread of control that can perform more
than one task at a time. UNIX support multiuser process but only support one
thread per process, Solaris supports multiple thread.

Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad


Operating Systems
Course Code: MCC510

Advantages of Thread:
➢ Responsiveness-Multithreading is an interactive application may allow a
program to continue running even if a part of it is blocked or is performing a
lengthy operation, thereby increasing responsiveness.
➢ Resource sharing-By default, threads share the memory and the resources of
the process to which they belong. The benefit of sharing code and data is that it
allows an application to have several different threads of activity within the
same address space.
➢ Economy-Allocating memory and resources for process creation is a costly
affairs as threads share the resources of the process to which they belong. It is
more economical to create context switch threads.
➢ Utilization of MP architectures-The benefit of multithreading can be greatly
increased in a multiprocessor architecture where threads may be running in
parallel on different processors.

Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad


Operating Systems
Course Code: MCC510

Types of Thread:
➢ User Level Thread-All the work of thread management is done by the
application and 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.
➢ Advantages-
➢ Thread switching does not require kernel mode privileges
➢ It can run on any operating system
➢ Scheduling can be application specific
➢ It is faster to create and manage
➢ Disadvantages-
➢ In a typical OS, most system calls are blocking
➢ Multithreaded application cannot take advantage of multiprocessing

Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad


Operating Systems
Course Code: MCC510

Types of Thread:
➢ Kernel Level Thread-Thread management done by the kernel. There is no
thread management code in the application area. Kernel threads are supported
directly by the OS. e.g., Windows XP/2000, Solaris, Linux,Tru64 UNIX, Mac
OS X
➢ Advantages-
➢ Kernel can simultaneously schedule multiple threads from the same process on
multiple processes
➢ If one thread in a process is blocked then the kernel can schedule another thread
of the same process
➢ Kernel routine themselves multithreaded.
➢ Disadvantages-
➢ Kernel thread are generally slower to create and mange
➢ Transfer of control from one thread to another thread within the same process
requires a mode switch to the kernel.

Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad


Operating Systems
Course Code: MCC510

Difference between User and Kernel level Threads:

➢ User Level thread Kernel Level Thread


➢ Faster to create and manage ➢ Slower to create and manage
➢ Implemented by thread library at ➢ OS support directly to Kernel threads
the user level
➢ Run on any OS
➢ Kernel level threads are specific to the
➢ Support provided at the user level OS
➢ Multithreaded application cannot ➢ Support provided by kernel
take advantage of multiprocessing ➢ Kernel routine themselves
multithreaded.

Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad


Operating Systems
Course Code: MCC510

Difference between Process and Thread:

➢ Process ➢ Thread
➢ Heavy weight process ➢ Light weight process
➢ Process switching needs interface
with OS ➢ Thread switching does not need to call
➢ In multiple process implementation, a OS and cause an interrupt to the
each process executes the same code kernel
but has its own memory and file
resources ➢ All threads can share same set of open
➢ If one server process is blocked then files, child processes.
no other server process can execute ➢ While one server thread is blocked
until the first process unblocked.
and waiting, second thread in the same
➢ In multiple process, each process
operates independently task could run.
➢ One thread can read, write or even
completely wipe out another thread
stack.
Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad
Operating Systems
Course Code: MCC510
Multithreading Models:
➢ 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.
➢ In this model, developers can create as many user thread as necessary
and the corresponding kernel threads can run in parallel on a
multiprocessor.
➢ Examples-Solaris prior to version 9, Windows NT/2000 with the thread
fiber package

Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad


Operating Systems
Course Code: MCC510
Multithreading Models:
➢ Many to One Model- In this model, many user level threads maps to
the one kernel thread.
➢ Thread management done in user space only.
➢ If thread makes a blocking system call then the entire process will be
blocked.
➢ Only one thread can access the kernel at a time so multiple thread are
unable to run in parallel on a multiprocessor.
➢ Examples-Solaris Green Thread, GNU Portable thread

Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad


Operating Systems
Course Code: MCC510
Multithreading Models:
➢ One to One Model- In this model, there is one to one correspondence
between user level thread and kernel level thread
➢ It provides more concurrency than many to one model by allowing
another thread to run when thread makes a blocking system call. It also
allow multiple thread to run in parallel on a multiprocessor.
➢ 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.
➢ Examples- Windows NT/XP/2000, Linux, Solaris 9 and later

Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad


Operating Systems
Course Code: MCC510
Thread Library:
➢ A thread library provides the programmer with an API for creating and
managing threads.
➢ Two Approaches for Implementing a Thread library.
➢ The first approach is to provide a library entirely in user space with no kernel
support. All code and data structures for the library exist in user space.
➢ The second approach is to implement a kernel level library supported directly by
the OS. The code and data structures for the library exist in the kernel space.
➢ There are three main thread libraries which are in use such as Posix P
threads, Win 32 threads and Java threads.

Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad


Operating Systems
Course Code: MCC510
Threading Issues:
➢ Semantics of fork() and exec() system calls
➢ Thread cancellation
➢ Signal Handling
➢ Thread Pools
➢ Thread Specific data
➢ Schedular Activation

Instructor: Prof M K Singh, Department of Mathematics and Computing, IIT(ISM) Dhanbad

You might also like