Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.

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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 6: Threads Chapter 4.
CHAPTER 5 THREADS & MULTITHREADING 1. Single and Multithreaded Processes 2.
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
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 4: Threads.
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 ©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.
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.
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.
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.
Operating System Principles Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
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: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Multithreaded Programming Overview.
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.
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.
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.
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.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Typical Program Processor utilization?
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
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 (7 th Edition)
Threads by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
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
Chapter 4: Threads.
Chapter 4: Multithreaded Programming
Chapter 4: Threads.
Chapter 4: Threads.
Operating System Concepts
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Multithreaded Programming
Chapter 4: Threads.
Presentation transcript:

Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads

4.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

4.3 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems To discuss the APIs for the Pthreads, Win32, and Java thread libraries To examine issues related to multithreaded programming

4.4 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Threads A thread, sometimes called a lightweight process(LWP), is a basic unit of CPU utilization and executes within the space of the process that creates it. A thread behave like a process with in a process but is does not have a its own PCB..

4.5 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Threads…. It comprises a thread ID, a program counter, register set stack. It shares with other threads belonging to the same process its code sections, data sections Any operating system resources, which are available to the task. A traditional (or heavyweight) process has a single thread of control. If a process has multiple threads of control, it can perform more than one task at a time

4.6 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Motivation Threads run within application Multiple tasks with the application can be implemented by separate threads Update display Fetch data Spell checking Answer a network request Process creation is heavy-weight while thread creation is light-weight Can simplify code, increase efficiency Kernels are generally multithreaded

4.7 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Multithreading Multithreading allows operating system to execute different thread simultaneously. A Web browser might have one thread display images or text while another thread retrieves data from the network, for example. A word processor may have a thread for displaying graphics, another thread for responding to keystrokes from the user, and a third thread for performing spelling and grammar checking in the background.

4.8 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition In certain situations, a single application may be required to perform several similar tasks. For example, a Web server accepts client requests for Web pages, images, sound, and so forth. A busy Web server may have several (perhaps thousands of) clients concurrently accessing it. If the Web server ran as a traditional single threaded process, it would be able to service only one client at a time, and a client might have to wait a very long time for its request to be serviced.

4.9 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Single and Multithreaded Processes

4.10 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition 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, thereby increasing responsiveness to user. Resource Sharing By default, thread share the memory and resources of the process to which they belong, Code sharing allows an application to have several different threads of activity all within the same address space. Economy Allocating memory and resources for process creation is costly. Alternatively, because threads share resources of the process to which they belong, it is more economical to create and context switch threads. Scalability The benefits of multithreading can be greatly increased in a multiprocessor environment, where each thread may be running in parallel on a different processor. A single thread process can only run on one CPU no matter how many are available.

4.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Disadvantages Resource sharing Whereas resource sharing is one the major advantages of thread. It is also a disadvantage because proper synchronization is needed between threads for accessing the shared resource Difficult Programming model It is difficult to write, debug and maintain multi-threaded programs for an average user. This is particularly true when is comes to writing code for synchronized access to shared resources.

4.12 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Multicore Programming Multicore systems putting pressure on programmers, challenges include: Dividing activities Balance Data splitting Data dependency Testing and debugging

4.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Dividing activities. This involves examining applications to find areas that can be divided into separate, concurrent tasks and thus can run in parallel on individual cores.

4.14 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Balance. While identifying tasks that can run in parallel, programmers must also ensure that the tasks perform equal work of equal value. In some instances, a certain task may not contribute as much value to the overall process as other tasks; using a separate execution core to run that task may not be worth the cost. Data splitting. Just as applications are divided into separate tasks, the data accessed and manipulated by the tasks must be divided to run on separate cores.

4.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Data dependency. The data accessed by the tasks must be examined for dependencies between two or more tasks. In instances where one task depends on data from another, programmers must ensure that the execution of the tasks is synchronized to accommodate the data dependency. Testing and debugging. When a program is running in parallel on multiple cores, there are many different execution paths. Testing and debugging such concurrent programs is inherently more difficult than testing and debugging single-threaded applications.

4.16 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Concurrent Execution on a Single-core System

4.17 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Parallel Execution on a Multicore System

4.18 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition User and Kernel threads Thread may handled at different levels. There are two types of thread to be managed in a modern system. These are known as user Threads and Kernel threads.

4.19 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition User Threads Thread management done by user-level threads library. User threads are implemented in user level libraries instead of system calls. The threading switching does not need to call operating system. It does not cause interrupt to the kernel. Three primary thread libraries: POSIX Pthreads Win32 threads Java threads

4.20 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Kernel Threads Supported within the Kernel of the operating system. All modern operating system support kernel level threads. They allow the kernel to perform multiple tasks and to service multiple kernel system calls simultaneously. Examples Windows XP/2000 Solaris Linux Tru64 UNIX Mac OS X

4.21 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Multithreading Models Many-to-One One-to-One Many-to-Many

4.22 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Many-to-One In many-to-one model, many user level threads are mapped to one kernel level thread. It is efficient because it is implemented in user space. A process using this model will blocked entirely if a thread makes a blocking system call. Only one thread can access the kernel at a time so it cannot run in parallel on multiprocessor. Many user-level threads mapped to single kernel thread Examples: Solaris Green Threads GNU Portable Threads

4.23 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Many-to-One Model

4.24 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition One-to-One In one-to-one model, each user thread is mapped to a kernel thread. It provides more concurrency because it allows an other thread to execute if a thread makes a blocking system call. Each user-level thread maps to kernel thread Examples Windows NT/XP/2000 Linux Solaris 9 and later

4.25 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition One-to-one Model

4.26 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition 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

4.27 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Many-to-Many Model

4.28 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition 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

4.29 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Two-level Model

Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition End of Chapter 4