Chapter 5: Threads - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Chapter 5: Threads

Description:

Thread management done by user-level threads library. The library provides support for ... or duplicates only the thread that involved the fork system call. ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 22
Provided by: marily207
Category:

less

Transcript and Presenter's Notes

Title: Chapter 5: Threads


1
Chapter 5 Threads
  • Overview
  • Multithreading Models
  • Threading Issues
  • Pthreads
  • Solaris 2 Threads
  • Windows 2000 Threads
  • Linux Threads
  • Java Threads

2
Single and Multithreaded Processes
  • Thread a lightweight process (LWP) , a basic
    unit of CPU utilization

3
Benefits
  • Responsiveness
  • Multithreading an interactive application may
    allow a program to continue running even if part
    of it is blocked or is performing a lengthy
    operation.
  • Resource Sharing
  • By default, threads share the memory and the
    resources of processes to which they belong.
  • Economy
  • Allocating memory and resources for process
    creation is costly.
  • It is more economical to create and context
    switch threads.
  • Utilization of MP Architectures
  • In a multiprocessor architecture, each thread
    may be running in parallel on a different
    processor

4
User Threads
  • Thread management done by user-level threads
    library
  • The library provides support for thread
    creation, scheduling, and management with no
    support from kernel.
  • Examples
  • - POSIX Pthreads
  • - Mach C-threads
  • - Solaris threads

5
Kernel Threads
  • Supported by the Kernel (OS)
  • Examples
  • - Windows 95/98/NT/2000
  • - Solaris
  • - Tru64 UNIX
  • - BeOS
  • - Linux

6
Multithreading Models
  • Many-to-OneMaps many user-level threads to one
    kernel thread.
  • One-to-OneMaps each user-level thread to a
    kernel thread.
  • Many-to-Many
  • Multiplexes many user-level threads to a small
    or equal number of kernel threads.

7
Many-to-One
  • Many user-level threads mapped to single kernel
    thread.
  • Used on systems that do not support kernel
    threads.
  • Thread management is done in user space
  • It is efficient
  • The entire process will block if a thread makes a
    blocking system call
  • Multiple threads are unable to run in parallel on
    multiprocessors.

8
Many-to-One Model
9
One-to-One
  • Each user-level thread maps to a kernel thread.
  • Creating a user thread requires creating the
    corresponding kernel thread.
  • The number of threads supported by the system is
    restricted.
  • Examples
  • - Windows 95/98/NT/2000
  • - OS/2

10
One-to-one Model
11
Many-to-Many Model
  • Allows many user level threads to be mapped to
    many kernel threads.
  • Allows the operating system to create a
    sufficient number of kernel threads.
  • Solaris 2
  • Windows NT/2000 with the ThreadFiber package

12
Many-to-Many Model
13
Threading Issues
  • Semantics of fork() and exec() system calls.
  • Fork() duplicates all threads or duplicates only
    the thread that involved the fork system call.
  • Exec() the program specified in the parameter to
    the exec will replace the entire process.
  • Thread cancellation.
  • Asynchronous cancellation One thread immediately
    terminates the target thread.
  • Deferred cancellation The target thread can
    periodically check if it should terminate.
    cancellation points

14
Threading Issues (cont.)
  • Signal handling
  • A signal is generated by the occurrence of a
    particular event.
  • A generated signal is delivered to a process.
  • Once delivered, the signal must be handled.
  • -- 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 thread to receive all
    signals for the process.
  • Thread pools
  • to create number of threads at process startup
    and place them into a pool.
  • Thread specific data

15
Pthreads
  • a POSIX standard (IEEE 1003.1c) API for thread
    creation and synchronization. user-level thread
    library
  • API specifies behavior of the thread library,
    implementation is up to development of the
    library.
  • Common in UNIX operating systems.

16
Solaris 2 Threads
Solaris 2 a version of UNIX with Support for
threads at the kernel and user
levels, SMP, and real-time scheduling.
17
Solaris Process
18
Windows 2000 Threads
  • Implements the one-to-one mapping.
  • Each thread contains
  • - a thread id
  • - register set
  • - separate user and kernel stacks
  • - private data storage area ( used by various
    run-time
  • libraries and dynamic link libraries (DLLs).

19
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)

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

21
Java Thread States
Write a Comment
User Comments (0)
About PowerShow.com