Operating System Principles - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Operating System Principles

Description:

Operating System Principles Ku-Yaw Chang canseco_at_mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 29
Provided by: IBM7185
Category:

less

Transcript and Presenter's Notes

Title: Operating System Principles


1
Operating System Principles
  • Ku-Yaw Chang
  • canseco_at_mail.dyu.edu.tw
  • Assistant Professor, Department of Computer
    Science and Information Engineering
  • Da-Yeh University

2
Chapter 4Multithreaded Programming
  • A process
  • With a single thread of control
  • With multiple threads of control
  • Multithreaded computer systems
  • Pthreads
  • Windows 32 threads
  • Java thread libraries
  • Windows XP and Linux
  • Support at the kernel level

3
Chapter 4Multithreaded Programming
  1. Overview
  2. Multithreading Models
  3. Thread Libraries
  4. Threading Issues
  5. Operating-System Examples
  6. Summary
  7. Exercises

4
4.1 Overview
  • A thread
  • A basic unit of CPU utilization
  • A thread ID
  • A program counter
  • A register set
  • A stack
  • Called a lightweight process (LWP)
  • A traditional process has a single thread of
    control, called a heavyweight process (HWP)

5
Single-threaded and Multithreaded processes
6
4.1.1 Motivation
  • A web browser
  • One thread display images or text
  • Another thread retrieves data from the network
  • A word processor
  • One thread for displaying graphics
  • Another thread for reading keystrokes
  • Third thread for performing spelling and grammar
    checking

7
4.1.1 Motivation
  • If new process will perform the same tasks as the
    existing process, why incur all that overhead?
  • Process creation is very time-consuming and
    resource intensive.
  • Have the server run as a single process that
    accepts requests.

8
4.1.2 Benefits
  • Responsiveness
  • Allow a program to continue even if part of it is
    blocked or is performing a lengthy operation
  • Resource sharing
  • Memory
  • Different threads all within the same address
    space
  • Resources
  • Economy
  • More economical to create and context switch
    threads
  • Utilization of multiprocessor architectures
  • Increase concurrency

9
Chapter 4Multithreaded Programming
  1. Overview
  2. Multithreading Models
  3. Thread Libraries
  4. Threading Issues
  5. Operating-System Examples
  6. Summary
  7. Exercises

10
4.2 Multithreading Models
  • User threads
  • Implemented by a thread library at the user level
  • Supported above the kernel
  • Advantage
  • Fast to create and manage
  • Disadvantage
  • A thread may cause the entire process to block
  • Examples
  • POSIX Pthreads
  • Win32 threads
  • Java threads

11
4.2 Multithreading Models
  • Kernel threads
  • The kernel performs thread creation, scheduling,
    and management
  • Supported directly by OS
  • Advantage
  • Kernel can schedule another thread when a thread
    is blocked
  • Disadvantage
  • Slow to create and manage
  • Examples
  • Windows XP
  • Linux
  • Max OS X
  • Solaris
  • Tru64 Unix

12
4.2 Multithreading Models
  • Many systems provide support for both user and
    kernel threads
  • Different multithreading models
  • Many-to-one model
  • One-to-one model
  • Many-to-many model

13
4.2.1 Many-to-One Model
  • Many user-level threads mapped to one kernel
    thread

14
4.2.1 Many-to-One Model
  • Advantage
  • Efficient
  • Disadvantage
  • Entire process may block if a thread makes a
    blocking system call
  • Unable to run in parallel on multiprocessors
  • Used on systems that do not support kernel
    threads
  • Green threads a thread library available for
    Solaris
  • GNU Portable Threads

15
4.2.2 One-to-One Model
  • Each user thread mapped to one kernel thread

16
4.2.2 One-to-One Model
  • Advantage
  • More concurrency
  • Disadvantage
  • Overhead of creating kernel threads can burden
    the performance of an application
  • Restrict the number of threads
  • Example
  • Linux
  • Windows operating systems
  • Windows 95, 98, NT, 2000, and XP

17
4.2.3 Many-to-Many Model
  • Multiplex many user-level threads to a small or
    equal number of kernel threads two-level model

18
4.2.3 Many-to-Many Model
  • Advantage
  • Developers can create as many as user threads as
    wish
  • More concurrency
  • Example
  • IRIX
  • HP-UX
  • Tru64 Unix
  • Solaris prior to version 9

19
Chapter 4Multithreaded Programming
  1. Overview
  2. Multithreading Models
  3. Thread Libraries
  4. Threading Issues
  5. Operating-System Examples
  6. Summary
  7. Exercises

20
4.3 Thread Libraries
  • A thread library
  • Provide the programmer an API for creating and
    managing threads
  • Two primary approaches
  • A user-level library
  • Entirely in user space, with no kernel support
  • A local function call in user space
  • A kernel-level library
  • Supported by the operating system
  • A system call to the kernel

21
4.3 Thread Libraries
  • Three main thread libraries in use
  • POSIX Pthreads
  • A specification for thread behavior
  • not an implementation
  • Win32
  • Java

22
Chapter 4Multithreaded Programming
  1. Overview
  2. Multithreading Models
  3. Thread Libraries
  4. Threading Issues
  5. Operating-System Examples
  6. Summary
  7. Exercises

23
  • Be skipped

24
Chapter 4Multithreaded Programming
  1. Overview
  2. Multithreading Models
  3. Thread Libraries
  4. Threading Issues
  5. Operating-System Examples
  6. Summary
  7. Exercises

25
Summary
  • P.141 to P.142

26
Chapter 4Multithreaded Programming
  1. Overview
  2. Multithreading Models
  3. Thread Libraries
  4. Threading Issues
  5. Operating-System Examples
  6. Summary
  7. Exercises

27
Exercises
  • 4.3
  • 4.4

28
The End
Write a Comment
User Comments (0)
About PowerShow.com