Operating System
THREADS
Presented By:
SHIVAM SINGH
M.Tech
What Is Thread..?
• Thread is a Light Weight
Process.
• Each thread has its own stack,
PC, registers
− Share address space, files,…
PC
PC
PC
Files i/o
stacks
Gigabyte
Virtual
Address
Types of Threads
User Level
Thread (ULT) Kernel Level
Thread (KLT)
User-LevelThreads(ULTs)
Introduction
Thread management done
by user-level threads
library.
Three primary thread
libraries:
• POSIX Pthreads
• Win32 threads
• Java threads
Thread switching
does not require
kernel mode
privileges (no
mode switches)
Scheduling can
be application
specific
ULTs can run
on any OS
Disadvantages of ULTs
 In a typical OS many system calls are blocking.
 As a result, when a ULT executes a system call, not only
is that thread blocked, but all of the threads within the
process are blocked.
 In a pure ULT strategy, a multithreaded application cannot take
advantage of multiprocessing.
Overcoming ULT Disadvantages
Jacketing
• Converts a blocking system call into a non-
blocking system call.
Writing an application as multiple processes rather than
multiple threads.
Kernel-LevelThreads(KLTs)
Introduction
 Thread management is
done by the kernel (could
call them KMT)
• No thread management is
done by the application
• Windows is an example of
this approach
Advantages of KLTs
 The kernel can simultaneously schedule multiple threads from
the same process on multiple processors
 If one thread in a process is blocked, the kernel can schedule
another thread of the same process
Disadvantages of KLTs
 The transfer of control from one thread to another within
the same process requires a mode switch to the kernel
Operation User Level
Thread
Kernel Level
Thread
Processes
Null Fork
Signal Wait
34
37
948
441
11,300
1,840
Thread and Process Operation Latencies(µs)
Benefits of Threads
Takes less
time to
create a new
thread than a
process
Less time to
terminate a
thread than a
process
Switching
between two
threads takes less
time than
switching
between
processes
Threads enhance
efficiency in
communication
between programs
Summary
• User-level Threads
– created and managed by a threads library that runs in the user space
of a process
– a mode switch is not required to switch from one thread to another
– only a single user-level thread within a process can execute at a
time
– if one thread blocks, the entire process is blocked
• Kernel-level Threads
– threads within a process that are maintained by the kernel
– a mode switch is required to switch from one thread to another
– multiple threads within the same process can execute in parallel on
a multiprocessor
– blocking of a thread does not block the entire process
Thank You..!!

Threads

  • 1.
  • 2.
    What Is Thread..? •Thread is a Light Weight Process. • Each thread has its own stack, PC, registers − Share address space, files,… PC PC PC Files i/o stacks Gigabyte Virtual Address
  • 3.
    Types of Threads UserLevel Thread (ULT) Kernel Level Thread (KLT)
  • 4.
    User-LevelThreads(ULTs) Introduction Thread management done byuser-level threads library. Three primary thread libraries: • POSIX Pthreads • Win32 threads • Java threads
  • 5.
    Thread switching does notrequire kernel mode privileges (no mode switches) Scheduling can be application specific ULTs can run on any OS
  • 6.
    Disadvantages of ULTs In a typical OS many system calls are blocking.  As a result, when a ULT executes a system call, not only is that thread blocked, but all of the threads within the process are blocked.  In a pure ULT strategy, a multithreaded application cannot take advantage of multiprocessing.
  • 7.
    Overcoming ULT Disadvantages Jacketing •Converts a blocking system call into a non- blocking system call. Writing an application as multiple processes rather than multiple threads.
  • 8.
    Kernel-LevelThreads(KLTs) Introduction  Thread managementis done by the kernel (could call them KMT) • No thread management is done by the application • Windows is an example of this approach
  • 9.
    Advantages of KLTs The kernel can simultaneously schedule multiple threads from the same process on multiple processors  If one thread in a process is blocked, the kernel can schedule another thread of the same process
  • 10.
    Disadvantages of KLTs The transfer of control from one thread to another within the same process requires a mode switch to the kernel Operation User Level Thread Kernel Level Thread Processes Null Fork Signal Wait 34 37 948 441 11,300 1,840 Thread and Process Operation Latencies(µs)
  • 11.
    Benefits of Threads Takesless time to create a new thread than a process Less time to terminate a thread than a process Switching between two threads takes less time than switching between processes Threads enhance efficiency in communication between programs
  • 12.
    Summary • User-level Threads –created and managed by a threads library that runs in the user space of a process – a mode switch is not required to switch from one thread to another – only a single user-level thread within a process can execute at a time – if one thread blocks, the entire process is blocked • Kernel-level Threads – threads within a process that are maintained by the kernel – a mode switch is required to switch from one thread to another – multiple threads within the same process can execute in parallel on a multiprocessor – blocking of a thread does not block the entire process
  • 13.