Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.

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.
國立台灣大學 資訊工程學系 Chapter 4: Threads. 資工系網媒所 NEWS 實驗室 Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the.
Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 6: Threads Chapter 4.
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
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 CS 170 TY, Sept 2011.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 4 Multithreaded Programming Objectives Objectives To introduce a notion of.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 4: Threads.
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 &
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
國立台灣大學 資訊工程學系 Chapter 4: Threads. 資工系網媒所 NEWS 實驗室 Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the.
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.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Multithreaded Programming Overview.
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.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Multithreading Models Threading Issues Pthreads Solaris 2 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.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Overview Multithreading Models Threading Issues Pthreads Solaris 2 Threads Windows 2000 Threads Linux Threads Java 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.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
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 – 7 th edition, Jan 23, 2005 Outline n Overview n 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.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
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.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
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.
Introduction to threads
Chapter 4: Multithreaded Programming
Nadeem MajeedChoudhary.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Presentation transcript:

Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples

Based on Silberschatz, Galvin and Gagne  2009 What is a thread? A “thread” is a single sequential flow of control within a process. A thread runs within a process, sharing code with other threads. Multiple threads within a process can run concurrently. Thread also called “lightweight process” (just the execution context)

Based on Silberschatz, Galvin and Gagne  2009 Single and Multithreaded Processes Note! These are shared!

Based on Silberschatz, Galvin and Gagne  2009 Sharing State Recall that a child forked from a parent process is a replica of the parent.  Modifications to the state (ie: variables) are not visible to either side after forking.  Exchange of information must pass through an OS-provided channel. Threads are based on a model where threads spawned from a parent can see:  State residing within the parent.  State residing within other threads.  All through standard variables, not OS-provided mechanisms. From a programmability perspective, this makes building concurrent programs easier.

Based on Silberschatz, Galvin and Gagne  2009 Benefits Responsiveness, faster context switch Resource Sharing, economy Parallelism, utilization of multicore and multiprocessor architectures Fits client/server model well Scalability

Based on Silberschatz, Galvin and Gagne  2009 Threads and parallel systems Threads fit naturally onto parallel computers.  Such as multicore. Allows a programmer to build one program to use all of the cores.  Instead of a flock of coordinated processes. The thread abstraction facilitates:  Shared address spaces.  Independent units of execution that can be scheduled onto the parallel processing elements (cores).

Based on Silberschatz, Galvin and Gagne  2009 Multicore Programming Multicore systems putting pressure on programmers, challenges include  Dividing activities  Balance  Data splitting  Data dependency  Testing and debugging

Based on Silberschatz, Galvin and Gagne  2009 Concurrent Execution on a Single-core System On single core, must run one task after the other. Given task T1, T2, T3, T4 capable of running concurrently.

Based on Silberschatz, Galvin and Gagne  2009 Parallel Execution on a Multicore System

Based on Silberschatz, Galvin and Gagne  2009 Multithreaded Server Architecture This can be done with parent and child processes, but less efficient, easier to share resources with threads.

Based on Silberschatz, Galvin and Gagne  2009 Kernel Threads Supported by the kernel Examples  Windows XP/2000  Solaris  Linux  Tru64 UNIX  Mac OS X

Based on Silberschatz, Galvin and Gagne  2009 User Threads Thread management done by user-level threads library. OS kernel does not manage threads (OS manages processes) User threads cheap, efficient. Creating threads, switching among threads, synchronizing threads done through procedure calls. Three primary user-level thread libraries:  POSIX Pthreads  Win32 threads  Java threads

Based on Silberschatz, Galvin and Gagne  2009 Kernel v. User Threads Kernel threads not well-suited to fine-grained concurrency, too much overhead as switching between kernel threads involves invoking the kernel User-level threads allow fast switching among threads User-level threads operations 100x faster than kernel threads. However, because user-level threads are invisible to the OS, poor performance can result  Scheduling a process with idle threads  Blocking a process whose thread has requested I/O even though it has other runnable threads

Based on Silberschatz, Galvin and Gagne  2009 Multithreading Models Many-to-One One-to-One Many-to-Many

Based on Silberschatz, Galvin and Gagne  2009 Many-to-One Many user-level threads mapped to single kernel thread Examples:  Solaris Green Threads  GNU Portable Threads

Based on Silberschatz, Galvin and Gagne  2009 Many-to-One Model

Based on Silberschatz, Galvin and Gagne  2009 One-to-One Each user-level thread maps to kernel thread Examples  Windows NT/XP/2000  Linux  Solaris 9 and later

Based on Silberschatz, Galvin and Gagne  2009 One-to-one Model

Based on Silberschatz, Galvin and Gagne  2009 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 prior to version 9 Windows NT/2000 with the ThreadFiber package

Based on Silberschatz, Galvin and Gagne  2009 Many-to-Many Model

Based on Silberschatz, Galvin and Gagne  2009 Two-level Model Similar to M:M, except that it allows a user thread to be bound to kernel thread Examples  IRIX  HP-UX  Tru64 UNIX  Solaris 8 and earlier

Based on Silberschatz, Galvin and Gagne  2009 Two-level Model

Based on Silberschatz, Galvin and Gagne  2009 Thread Libraries Thread library provides programmer with API for creating and managing threads  create, fork, start, stop, block, yield, exit Two primary ways of implementing  Library entirely in user space  Kernel-level library supported by the OS

Based on Silberschatz, Galvin and Gagne  2009 Pthreads May be provided either as user-level or kernel-level A POSIX standard (IEEE c) API for thread creation and synchronization API specifies behavior of the thread library, implementation is up to development of the library Common in UNIX operating systems (Solaris, Linux, Mac OS X)

Based on Silberschatz, Galvin and Gagne  2009 Java Threads Java threads are managed by the JVM Typically implemented using the threads model provided by underlying OS Java threads may be created by:  Extending Thread class  Implementing the Runnable interface

Based on Silberschatz, Galvin and Gagne  2009 Operating System Examples Windows XP Threads Linux Thread

Based on Silberschatz, Galvin and Gagne  2009 Windows XP Threads Implements the one-to-one mapping, kernel-level Each thread contains  A thread id  Register set  Separate user and kernel stacks  Private data storage area The register set, stacks, and private storage area are known as the context of the threads The primary data structures of a thread include:  ETHREAD (executive thread block)  KTHREAD (kernel thread block)  TEB (thread environment block)

Based on Silberschatz, Galvin and Gagne  2009 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)