SlideShare a Scribd company logo
OPERATING SYSTEMS

     Threads


    Jerry Breecher


        4: Threads   1
OPERATING SYSTEM
             Threads
         What Is In This Chapter?
Overview
Multithreading Models
Threading Issues
Pthreads
Windows XP Threads
Linux Threads
Java Threads


                        4: Threads   2
Single and
THREADS                Multithreaded
                        Processes




          4: Threads              3
Benefits
THREADS

Responsiveness

Resource Sharing

Economy

Utilization of MP Architectures




                      4: Threads              4
THREADS                                       User Threads
Thread management done by user-level threads library

Examples
- POSIX Pthreads
- Mach C-threads
- Solaris threads

 Supported by the Kernel
                                            Kernel Threads
 Examples
 - Windows 95/98/NT/2000
 - Solaris
 - Tru64 UNIX
 - BeOS
 - Linux                   4: Threads                   5
Multithreading
THREADS                               Models


Many-to-One

                            How do user and kernel
One-to-One                  threads map into each other?


Many-to-Many




               4: Threads                              6
THREADS                             Many-to-One


Many user-level threads
mapped to single kernel
thread.

Used on systems that
do not support kernel
threads.
Examples:
 Solaris Green Threads
 GNU Portable Threads




                          4: Threads           7
THREADS                                      One-to-One
Each user-level thread maps to kernel thread.

Examples
- Windows 95/98/NT/2000
- Linux




                             4: Threads                8
Threading Issues
    THREADS
Semantics of fork() and exec() system calls
  Does fork() duplicate only the calling thread or all threads?

Thread cancellation
  Terminating a thread before it has finished
  Two general approaches:
     Asynchronous cancellation terminates the target thread
     immediately
     Deferred cancellation allows the target thread to
     periodically check if it should be cancelled




                               4: Threads                         9
Threading Issues
     THREADS
Signal handling
   Signals are used in UNIX systems to notify a process that a particular event
   has occurred
   A signal handler is used to process signals
    1. Signal is generated by particular event
    2. Signal is delivered to a process
    3. Signal is handled
   Options:
       Deliver the signal to the thread to which the signal applies
       Deliver the signal to every thread in the process
       Deliver the signal to certain threads in the process
       Assign a specific threa to receive all signals for the process
Thread pools
   Create a number of threads in a pool where they await work
   Advantages:
       Usually slightly faster to service a request with an existing thread than
       create a new thread
       Allows the number of threads in the application(s) to be bound to the size
       of the pool                     4: Threads                                10
Threading Issues
   THREADS
Thread specific data
  Allows each thread to have its own copy of data
  Useful when you do not have control over the thread creation process
  (i.e., when using a thread pool)

Scheduler activations
  Many:Many models require communication to maintain the appropriate
  number of kernel threads allocated to the application
  Scheduler activations provide upcalls - a communication mechanism
  from the kernel to the thread library
  This communication allows an application to maintain the correct
  number kernel threads




                               4: Threads                         11
THREADS                        Various Implementations
PThreads
  A POSIX standard (IEEE 1003.1c) API for thread creation and
  synchronization
  API specifies behavior of the thread library, implementation is up to
  development of the library
  Common in UNIX operating systems (Solaris, Linux, Mac OS X)

Windows Threads
  Implements the one-to-one mapping
  Each thread contains
     A thread id
     Register set
     Separate user and kernel stacks
     Private data storage area
  The register set, stacks, and private storage area are known as the
  context of the threads
                                 4: Threads                          12
THREADS                            Various Implementations
Linux Threads
   Linux refers to them as tasks rather than threads
   Thread creation is done through clone() system call
   clone() allows a child task to share the address space of the parent task (process)

Java Threads
   Java threads may be created by:
      Extending Thread class
      Implementing the Runnable interface
   Java threads are managed by the JVM.




                                     4: Threads                               13
Threads
                           WRAPUP

We’ve looked in detail at how threads work. Specifically we’ve looked
at:

Multithreading Models
Threading Issues
Pthreads
Windows XP Threads
Linux Threads
Java Threads




                             4: Threads                        14

More Related Content

PPT
Chapter 4 - Threads
PPT
Ch5 OS
 
PPT
Ch4 Threads
PPT
Operating System 4
PDF
OS - Thread
PPTX
Threads
PPTX
Chapter 4 - Threads
Ch5 OS
 
Ch4 Threads
Operating System 4
OS - Thread
Threads

What's hot (20)

PDF
Operating Systems 1 (7/12) - Threads
PPTX
Threads (operating System)
PPT
Operating System Chapter 4 Multithreaded programming
PDF
Thread
PDF
4 threads
PPT
multi-threading
PPTX
Thread management
PPT
Posix threads(asha)
PPT
Operating System-Threads-Galvin
PPT
PPT
Lecture 9 -_pthreads-linux_threads
PPT
PPTX
Thread (Operating System)
PPTX
Networking threads
PPTX
Multi threaded programming
PPTX
Threads
PDF
Multithreading
PPTX
Threads and multi threading
PPTX
Operating system: threads(mulithreading,benefits of threads, types of thread)
PPTX
THREADS of Operating System by Noman Zahid
Operating Systems 1 (7/12) - Threads
Threads (operating System)
Operating System Chapter 4 Multithreaded programming
Thread
4 threads
multi-threading
Thread management
Posix threads(asha)
Operating System-Threads-Galvin
Lecture 9 -_pthreads-linux_threads
Thread (Operating System)
Networking threads
Multi threaded programming
Threads
Multithreading
Threads and multi threading
Operating system: threads(mulithreading,benefits of threads, types of thread)
THREADS of Operating System by Noman Zahid
Ad

Viewers also liked (20)

PDF
ใบงานที่ 3 ขอบข่ายและประเภทของโครงงาน
PDF
QReequn presentation
PPTX
Aros Mini MBA - infomateriale om lederuddannelsen (minimba)
PDF
Networked Dynamic Systems: Identification, Controllability, and Randomness
PPT
Butterfly
PDF
Making Infrastructure as Awesome as Agile Development
DOC
6 матем
PPT
Por qué seguimos leyendo
PDF
Pdf 1 presentacion 22-03-13 scdad eh
PDF
Network Identification via Node Knock-out
PDF
PIEAS
DOCX
ISEA Paper 2011
PPTX
Presentation1
PPT
愛的承諾Apo 2010年版com99080204
PPTX
Energofor
PPT
PDF
Business Modelling
PDF
MY POTFOLIO
PDF
SHLOMO - VOL.2 - September 2012
PDF
Marta medina cv
ใบงานที่ 3 ขอบข่ายและประเภทของโครงงาน
QReequn presentation
Aros Mini MBA - infomateriale om lederuddannelsen (minimba)
Networked Dynamic Systems: Identification, Controllability, and Randomness
Butterfly
Making Infrastructure as Awesome as Agile Development
6 матем
Por qué seguimos leyendo
Pdf 1 presentacion 22-03-13 scdad eh
Network Identification via Node Knock-out
PIEAS
ISEA Paper 2011
Presentation1
愛的承諾Apo 2010年版com99080204
Energofor
Business Modelling
MY POTFOLIO
SHLOMO - VOL.2 - September 2012
Marta medina cv
Ad

Similar to Section04 threads (20)

PPT
Operating Systems - "Chapter 4: Multithreaded Programming"
PPT
4.Threads
PPT
Threads in Operating systems and concepts
PDF
CH04.pdf
PDF
Basic Threads in Advanced operating system
PPT
Ch04 threads
PDF
Ch4 threads
PDF
Multithreaded Programming in oprating system
PDF
Sucet os module_2_notes
PPT
Operating Systems Chapter 4444444444.ppt
PPTX
OS Module-2.pptx
PPTX
Operating systems - Introduction to Threads
PPTX
Chapter 4 - Operating Systems Threads.pptx
PPT
15 threads
PDF
The Thread Chapter 4 of Operating System
PPTX
Lecture 3- Threads (1).pptx
PPTX
Chapter04 new
PPTX
Threading.pptx
PPT
Operating System 4 1193308760782240 2
PDF
Threads operating system slides easy understand
Operating Systems - "Chapter 4: Multithreaded Programming"
4.Threads
Threads in Operating systems and concepts
CH04.pdf
Basic Threads in Advanced operating system
Ch04 threads
Ch4 threads
Multithreaded Programming in oprating system
Sucet os module_2_notes
Operating Systems Chapter 4444444444.ppt
OS Module-2.pptx
Operating systems - Introduction to Threads
Chapter 4 - Operating Systems Threads.pptx
15 threads
The Thread Chapter 4 of Operating System
Lecture 3- Threads (1).pptx
Chapter04 new
Threading.pptx
Operating System 4 1193308760782240 2
Threads operating system slides easy understand

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
Teaching material agriculture food technology
PPTX
Cloud computing and distributed systems.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Teaching material agriculture food technology
Cloud computing and distributed systems.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf
Review of recent advances in non-invasive hemoglobin estimation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Advanced methodologies resolving dimensionality complications for autism neur...
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation_ Review paper, used for researhc scholars
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Section04 threads

  • 1. OPERATING SYSTEMS Threads Jerry Breecher 4: Threads 1
  • 2. OPERATING SYSTEM Threads What Is In This Chapter? Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads 4: Threads 2
  • 3. Single and THREADS Multithreaded Processes 4: Threads 3
  • 5. THREADS User Threads Thread management done by user-level threads library Examples - POSIX Pthreads - Mach C-threads - Solaris threads Supported by the Kernel Kernel Threads Examples - Windows 95/98/NT/2000 - Solaris - Tru64 UNIX - BeOS - Linux 4: Threads 5
  • 6. Multithreading THREADS Models Many-to-One How do user and kernel One-to-One threads map into each other? Many-to-Many 4: Threads 6
  • 7. THREADS Many-to-One Many user-level threads mapped to single kernel thread. Used on systems that do not support kernel threads. Examples: Solaris Green Threads GNU Portable Threads 4: Threads 7
  • 8. THREADS One-to-One Each user-level thread maps to kernel thread. Examples - Windows 95/98/NT/2000 - Linux 4: Threads 8
  • 9. Threading Issues THREADS Semantics of fork() and exec() system calls Does fork() duplicate only the calling thread or all threads? Thread cancellation Terminating a thread before it has finished Two general approaches: Asynchronous cancellation terminates the target thread immediately Deferred cancellation allows the target thread to periodically check if it should be cancelled 4: Threads 9
  • 10. Threading Issues THREADS Signal handling Signals are used in UNIX systems to notify a process that a particular event has occurred A signal handler is used to process signals 1. Signal is generated by particular event 2. Signal is delivered to a process 3. Signal is handled Options: Deliver the signal to the thread to which the signal applies Deliver the signal to every thread in the process Deliver the signal to certain threads in the process Assign a specific threa to receive all signals for the process Thread pools Create a number of threads in a pool where they await work Advantages: Usually slightly faster to service a request with an existing thread than create a new thread Allows the number of threads in the application(s) to be bound to the size of the pool 4: Threads 10
  • 11. Threading Issues THREADS Thread specific data Allows each thread to have its own copy of data Useful when you do not have control over the thread creation process (i.e., when using a thread pool) Scheduler activations Many:Many models require communication to maintain the appropriate number of kernel threads allocated to the application Scheduler activations provide upcalls - a communication mechanism from the kernel to the thread library This communication allows an application to maintain the correct number kernel threads 4: Threads 11
  • 12. THREADS Various Implementations PThreads A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization API specifies behavior of the thread library, implementation is up to development of the library Common in UNIX operating systems (Solaris, Linux, Mac OS X) Windows Threads Implements the one-to-one mapping Each thread contains A thread id Register set Separate user and kernel stacks Private data storage area The register set, stacks, and private storage area are known as the context of the threads 4: Threads 12
  • 13. THREADS Various Implementations Linux Threads Linux refers to them as tasks rather than threads Thread creation is done through clone() system call clone() allows a child task to share the address space of the parent task (process) Java Threads Java threads may be created by: Extending Thread class Implementing the Runnable interface Java threads are managed by the JVM. 4: Threads 13
  • 14. Threads WRAPUP We’ve looked in detail at how threads work. Specifically we’ve looked at: Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads 4: Threads 14