Docsity

Threads Three - Operating Systems - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Threads Three - Operating Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

4: Threads 1

OPERATING SYSTEMS

Threads

4: Threads 2

What Is In This Chapter?

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

OPERATING SYSTEM

Threads

4: Threads 4

Benefits

  • Responsiveness
  • Resource Sharing
  • Economy
  • Utilization of MP Architectures

THREADS

4: Threads 5

User Threads

  • Thread management done by user-level threads library
  • Examples
    • POSIX Pthreads
    • Mach C-threads
    • Solaris threads

THREADS

Kernel Threads

  • Supported by the Kernel
  • Examples
    • Windows 95/98/NT/
    • Solaris
    • Tru64 UNIX
    • BeOS
    • Linux

4: Threads 7

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

THREADS

4: Threads 8

One-to-One

  • Each user-level thread maps to kernel thread.
  • Examples
    • Windows 95/98/NT/
    • Linux

THREADS

4: Threads 10

Threading Issues

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

THREADS

4: Threads 11

Threading Issues

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

THREADS

4: Threads 13

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.

THREADS

4: Threads 14

WRAPUP

Threads

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