Operating System Principles Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.

Slides:



Advertisements
Similar presentations
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows.
Advertisements

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Threads. Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Threads.
Chapter 4: Multithreaded Programming
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 4: Multithreaded Programming
Course: Operating Systems Instructor: Umar Kalim NUST Institute of Information Technology, Pakistan Operating Systems.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 4 Multithreaded Programming Objectives Objectives To introduce a notion of.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Objectives To introduce a notion of a thread.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Thread definitions and relationship to process Multithreading.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads READ 4.1 & 4.2 NOT RESPONSIBLE FOR 4.3 &
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
Thread. A basic unit of CPU utilization. It comprises a thread ID, a program counter, a register set, and a stack. It is a single sequential flow of control.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Multithreaded Programming Overview.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 4 Operating Systems.
Chapter 4: Threads. 4.2 Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads.
Cosc 4740 Chapter 4 & 5 Threads & Scheduling. Motivation Threads run within application (process) Multiple tasks with the application can be implemented.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Operating System Concepts Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
CHAPTER 5: THREADS ( 线程 ) Overview Overview Multithreading Models (多线程模型) Multithreading Models (多线程模型) Thread Implementation Issues (线程实现事项) Thread Implementation.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Chapter 4: Threads. 2 Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads Modified from the slides of the text book. TY, Sept 2010.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Lecture 3 Threads Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
CS307 Operating Systems Threads Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2011.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Chapter 4: Threads 羅習五. Chapter 4: Threads Motivation and Overview Multithreading Models Threading Issues Examples – Pthreads – Windows XP Threads – Linux.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Contents 1.Overview 2.Multithreading Model 3.Thread Libraries 4.Threading Issues 5.Operating-system Example 2 OS Lab Sun Suk Kim.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Lecture 5. Example for periority The average waiting time : = 41/5= 8.2.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Multithreaded Programming.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Introduction to threads
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Threads.
Operating System Concepts
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Multithreaded Programming
Chapter 4: Threads.
Presentation transcript:

Operating System Principles Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University

2Ku-Yaw ChangChapter 4 Multithreaded Programming A process With a single thread of control With a single thread of control With multiple threads 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 Support at the kernel level

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

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

5Ku-Yaw ChangChapter 4 Multithreaded Programming Single-threaded and Multithreaded processes

6Ku-Yaw ChangChapter 4 Multithreaded Programming Motivation A web browser One thread display images or text One thread display images or text Another thread retrieves data from the network Another thread retrieves data from the network A word processor One thread for displaying graphics One thread for displaying graphics Another thread for reading keystrokes Another thread for reading keystrokes Third thread for performing spelling and grammar checking Third thread for performing spelling and grammar checking

7Ku-Yaw ChangChapter 4 Multithreaded Programming 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. Process creation is very time-consuming and resource intensive. Have the server run as a single process that accepts requests. Have the server run as a single process that accepts requests.

8Ku-Yaw ChangChapter 4 Multithreaded Programming Benefits Responsiveness Allow a program to continue even if part of it is blocked or is performing a lengthy operation Allow a program to continue even if part of it is blocked or is performing a lengthy operation Resource sharing Memory Memory Different threads all within the same address space Resources ResourcesEconomy More economical to create and context switch threads More economical to create and context switch threads Utilization of multiprocessor architectures Increase concurrency Increase concurrency

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

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

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

12Ku-Yaw ChangChapter 4 Multithreaded Programming 4.2 Multithreading Models Many systems provide support for both user and kernel threads Different multithreading models Different multithreading models Many-to-one model One-to-one model Many-to-many model

13Ku-Yaw ChangChapter 4 Multithreaded Programming Many-to-One Model Many user-level threads mapped to one kernel thread

14Ku-Yaw ChangChapter 4 Multithreaded Programming Many-to-One Model Advantage Efficient EfficientDisadvantage Entire process may block if a thread makes a blocking system call Entire process may block if a thread makes a blocking system call Unable to run in parallel on multiprocessors Unable to run in parallel on multiprocessors Used on systems that do not support kernel threads Green threads – a thread library available for Solaris Green threads – a thread library available for Solaris GNU Portable Threads GNU Portable Threads

15Ku-Yaw ChangChapter 4 Multithreaded Programming One-to-One Model Each user thread mapped to one kernel thread

16Ku-Yaw ChangChapter 4 Multithreaded Programming One-to-One Model Advantage More concurrency More concurrencyDisadvantage Overhead of creating kernel threads can burden the performance of an application Overhead of creating kernel threads can burden the performance of an application Restrict the number of threads Example Linux Linux Windows operating systems Windows operating systems Windows 95, 98, NT, 2000, and XP

17Ku-Yaw ChangChapter 4 Multithreaded Programming Many-to-Many Model Multiplex many user-level threads to a small or equal number of kernel threads – two-level model

18Ku-Yaw ChangChapter 4 Multithreaded Programming Many-to-Many Model Advantage Developers can create as many as user threads as wish Developers can create as many as user threads as wish More concurrency More concurrencyExample IRIX IRIX HP-UX HP-UX Tru64 Unix Tru64 Unix Solaris prior to version 9 Solaris prior to version 9

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

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

21Ku-Yaw ChangChapter 4 Multithreaded Programming 4.3 Thread Libraries Three main thread libraries in use POSIX Pthreads POSIX Pthreads A specification for thread behavior not an implementation not an implementation Win32 Win32 Java Java

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

23Ku-Yaw ChangChapter 4 Multithreaded Programming Be skipped

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

25Ku-Yaw ChangChapter 4 Multithreaded Programming Summary P.141 to P.142

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

27Ku-Yaw ChangChapter 4 Multithreaded Programming Exercises

The End