Operating System Concepts - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

Operating System Concepts

Description:

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

Number of Views:343
Avg rating:3.0/5.0
Slides: 47
Provided by: IBM62
Category:

less

Transcript and Presenter's Notes

Title: Operating System Concepts


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

2
Chapter 5 Threads
  • A process
  • With a single thread of control
  • With multiple threads of control
  • Multithreaded computer systems
  • Pthreads
  • Solaris 2 threads
  • Windows 2000 threads
  • Linux threads
  • Java threads

3
Chapter 5 Threads
  1. Overview
  2. Multithreading Models
  3. Threading Issues
  4. Pthreads
  5. Solaris 2 Threads
  1. Windows 2000 Threads
  2. Linux Threads
  3. Java Threads
  4. Summary
  5. Exercises

4
5.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- and Multithreaded processes
6
5.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
  • Process creation very heavyweight.
  • If new process will perform the same tasks as the
    existing process, why incur all that overhead?

7
5.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

8
5.1.3 User and Kernel Threads
  • 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
  • Mach C-threads
  • Solaris 2 UI-threads

9
5.1.3 User and Kernel Threads
  • 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 NT/2000
  • Solaris 2
  • BeOS
  • Tru64 Unix

10
5.1.3 User and Kernel Threads
  • Java threads
  • Created and managed by the Java virtual machine
    (JVM)
  • Do not fall under the realm of either user or
    kernel threads

11
Chapter 5 Threads
  1. Overview
  2. Multithreading Models
  3. Threading Issues
  4. Pthreads
  5. Solaris 2 Threads
  1. Windows 2000 Threads
  2. Linux Threads
  3. Java Threads
  4. Summary
  5. Exercises

12
5.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
5.2.1 Many-to-One Model
  • Many user-level threads mapped to one kernel
    thread
  • 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 2

14
5.2.1 Many-to-One Model
15
5.2.2 One-to-One Model
  • Each user thread mapped to one kernel thread
  • Advantage
  • More concurrency
  • Disadvantage
  • Overhead of creating kernel threads can burden
    the performance of an application
  • Restrict the number of threads
  • Example
  • Windows NT/2000 and OS/2

16
5.2.2 One-to-One Model
17
5.2.3 Many-to-Many Model
  • Multiplex many user-level threads to a small or
    equal number of kernel threads
  • Advantage
  • Developers can create as many as user threads as
    wish
  • More concurrency
  • Example
  • Solaris 2
  • Windows NT/2000 with the ThreadFiber package
  • IRIX
  • HP-UX
  • Tru64 Unix

18
5.2.3 Many-to-Many Model
19
Chapter 5 Threads
  1. Overview
  2. Multithreading Models
  3. Threading Issues
  4. Pthreads
  5. Solaris 2 Threads
  1. Windows 2000 Threads
  2. Linux Threads
  3. Java Threads
  4. Summary
  5. Exercises

20
5.3 Threading Issues
  • The fork and exec System Calls
  • Cancellation
  • Signal Handling
  • Thread Pools
  • Thread-Specific Data

21
5.3.1 The fork and execSystem Calls
  • One thread in a program calls fork
  • New process duplicate all threads
  • New process is single threaded
  • The exec system call works in the same way as
    described before.
  • Some systems have two versions of fork
  • If exec is called immediately, then duplicating
    all threads is unnecessary.
  • If not, the separate process should duplicate all
    threads.

22
5.3.2 Cancellation
  • Thread cancellation
  • The task of terminating a thread before it has
    completed
  • Target thread
  • The thread that is to be cancelled
  • Two different scenarios
  • Asynchronous cancellation
  • One thread immediately terminates the target
    threads.
  • Deferred cancellation
  • The target thread periodically checks if it is
    should terminate, allowing itself an opportunity
    to terminate itself in an orderly fashion.
  • Cancellation points (Pthreads)

23
5.3.3 Signal Handling
  • A signal
  • Used in Unix systems
  • Notify a process that a particular event has
    occurred
  • May be received either synchronously or
    asynchronously
  • All signals follow the same pattern
  • 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.

24
5.3.3 Signal Handling
  • Synchronous signal
  • An illegal memory access or divided by zero
  • Asynchronous signal
  • Terminating a process with specific keystrokes (
    ltcontrolgtltCgt )
  • Signal may be handled by
  • A default signal handler
  • Every signal has a default signal handler run by
    the kernel
  • A user-defined signal handler
  • Override the default signal handler

25
5.3.3 Signal Handling
  • Delivering signals is more complicated in
    multithreaded programs
  • 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

26
5.3.3 Signal Handling
  • Windows 2000
  • Does not explicitly support signals
  • Emulation using Asynchronous Procedure Calls
    (APCs)
  • Allow a thread to specify a function that is to
    be called when the thread receives notification
    of a particular event

27
5.3.4 Thread Pools
  • Potential problems
  • Amount of time required to create the thread
    prior to servicing the request
  • Unlimited threads could exhaust the system
    resources
  • Thread pool
  • To create a number of threads at process startup
    and place them in a pool
  • Sit and wait for work
  • A server receives a request, a thread is awaken
    from the pool
  • Once the thread completes its work, it returns to
    the pool
  • If the pools contains no available thread, the
    server waits until one become free

28
5.3.5 Thread-Specific Data
  • Threads belonging to a process share the data of
    the process.
  • One of the benefits of multithreaded programming
  • Each thread also needs its own copy of certain
    data called thread specific data

29
Chapter 5 Threads
  1. Overview
  2. Multithreading Models
  3. Threading Issues
  4. Pthreads
  5. Solaris 2 Threads
  1. Windows 2000 Threads
  2. Linux Threads
  3. Java Threads
  4. Summary
  5. Exercises

30
5.4 Pthreads
  • a POSIX standard (IEEE 1003.1c) API for thread
    creation and synchronization
  • A specification for thread behavior, not an
    implementation
  • Common in UNIX-based systems
  • Generally not supported in Windows systems

31
Chapter 5 Threads
  1. Overview
  2. Multithreading Models
  3. Threading Issues
  4. Pthreads
  5. Solaris 2 Threads
  1. Windows 2000 Threads
  2. Linux Threads
  3. Java Threads
  4. Summary
  5. Exercises

32
5.5 Solaris 2 Threads
  • Read it by yourself
  • P. 141 to 143

33
Chapter 5 Threads
  1. Overview
  2. Multithreading Models
  3. Threading Issues
  4. Pthreads
  5. Solaris 2 Threads
  1. Windows 2000 Threads
  2. Linux Threads
  3. Java Threads
  4. Summary
  5. Exercises

34
5.6 Windows 2000 Threads
  • Win32 API
  • Primary API for the family of MS OSs
  • Provide one-to-one mapping model
  • A fiber library provides the many-to-many model
  • Primary data structures
  • ETHREAD (executive thread block)
  • In kernel space
  • KTHREAD (kernel thread block)
  • In kernel space
  • TEB (Thread environment block)
  • User-space data structure

35
Chapter 5 Threads
  1. Overview
  2. Multithreading Models
  3. Threading Issues
  4. Pthreads
  5. Solaris 2 Threads
  1. Windows 2000 Threads
  2. Linux Threads
  3. Java Threads
  4. Summary
  5. Exercises

36
5.7 Linux Threads
  • Read it by yourself
  • P. 144 to 145

37
Chapter 5 Threads
  1. Overview
  2. Multithreading Models
  3. Threading Issues
  4. Pthreads
  5. Solaris 2 Threads
  1. Windows 2000 Threads
  2. Linux Threads
  3. Java Threads
  4. Summary
  5. Exercises

38
5.8 Java Threads
  • Java
  • Support threads at the language level
  • For the creation and management of threads
  • Threads are managed by JVM
  • Not by a user-level library or kernel
  • A Java program
  • Only a main method runs as a single thread in JVM

39
5.8.1 Thread Creation
  • Thread creation
  • To create a new class that derived from the
    Thread class
  • Override the run method of the Thread class
  • Calling the start method actually creates the new
    thread

40
Java Thread States
41
5.8.2 The JVM andthe Host Operation System
  • JVM does not indicate how Java thread are to be
    mapped to the underlying OS
  • Leaving the decision to the particular
    implementation of the JVM
  • Windows use one-to-one model

42
Chapter 5 Threads
  1. Overview
  2. Multithreading Models
  3. Threading Issues
  4. Pthreads
  5. Solaris 2 Threads
  1. Windows 2000 Threads
  2. Linux Threads
  3. Java Threads
  4. Summary
  5. Exercises

43
Summary
  • P.147

44
Chapter 5 Threads
  1. Overview
  2. Multithreading Models
  3. Threading Issues
  4. Pthreads
  5. Solaris 2 Threads
  1. Windows 2000 Threads
  2. Linux Threads
  3. Java Threads
  4. Summary
  5. Exercises

45
Exercises
  • 5.1
  • 5.2
  • 5.3
  • 5.8

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