Operating System Concepts

Slides:



Advertisements
Similar presentations
1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
Advertisements

CHAPTER 5 THREADS & MULTITHREADING 1. Single and Multithreaded Processes 2.
Chapter 4: Multithreaded Programming
Chapter 5 Threads os5.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Chapter 4: Multithreaded Programming
Course: Operating Systems Instructor: Umar Kalim NUST Institute of Information Technology, Pakistan Operating Systems.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 5: Threads 9/29/03+ Overview Benefits User and Kernel Threads Multithreading.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Objectives To introduce a notion of a thread.
Process Concept An operating system executes a variety of programs
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.
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.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Operating System Concepts Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
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.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
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.
1 OS Review Processes and Threads Chi Zhang
Cooperating Processes The concurrent processes executing in the operating system may be either independent processes or cooperating processes. A process.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Operating System Concepts
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.
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.
CMSC 421 Spring 2004 Section 0202 Part II: Process Management Chapter 5 Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Lecture 5. Example for periority The average waiting time : = 41/5= 8.2.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Threads Overview Benefits, User and Kernel Threads.
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Introduction to threads
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models Threading Issues
Operating System (013022) Dr. H. Iwidat
Operating System Concepts 7th Edition Abraham SilBerschatz Peter Baer Galvin Greg Gagne Prerequisite: CSE212.
Chapter 5: Threads Overview Multithreading Models(多线程模型)
Chapter 4: Multithreaded Programming
Chapter 3 Threads and Multithreading
Chapter 4: Multithreaded Programming
Threads & multithreading
Chapter 4: Threads.
Operating Systems (CS 340 D)
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4 Multithreading programming
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Multithreaded Programming
Operating Systems (CS 340 D)
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Threads.
Chapter 4:Threads Book: Operating System Principles , 9th Edition , Abraham Silberschatz, Peter Baer Galvin, Greg Gagne.
Presentation transcript:

Operating System Concepts Chapter #5: Threads Overview Multithreading Models Threading Issues Operating System Concepts

Operating System Concepts Threads (Cont.) A thread, sometimes called a lightweight process (LWP), is a basic unit of CPU utlization It comprises a thread ID, a program counter, a register set, and a stack. It shares with other threads belonging to the same process its code section, data section, and other OS resources., such as open files. A traditional (or heavyweight) process has a single thread of control. if the process has multiple threads of control, it can do more than one task at a time, Operating System Concepts

Operating System Concepts Threads (Cont.) Many software packages that run on modern desktop PCs are multithreaded. An application typically is implemented as a separate process with several threads of control. Examples: A web browser might have one thread display images or text while another thread retrieves data from the network. A word processor may have a thread for displaying graphics, another for reading keystrokes from the user, and a third thread for performing spelling and grammar checking in the background. Operating System Concepts

Multithreaded Process Address space + Threads + Resources Address space: contains code and data of a process. Threads: are individual execution contexts. Resources: are physical support necessary to run the process (memory, disk, …). Operating System Concepts

Single and Multithreaded Processes Operating System Concepts

Operating System Concepts Benefits Responsiveness: Example: a multithreaded web browser could still allow user interaction in one thread while an image is being loaded in another thread. Resource Sharing: By default, threads share the memory and the resources of the process to which they belong. The benefit: it allows an application to have several different threads of activity all within the same address space. Operating System Concepts

Operating System Concepts Benefits Economy: Allocating memory and resources for process creation is costly It is more economical to create and context switch threads because they share resources. In general, it is much more time consuming to create and manage processes than threads. Utilization of multiprocessor Architectures: Each thread may be running in parallel on a different processor A single-threaded process can only run on one CPU, no matter how many are available. Multithreading on a multi-CPU machine increases concurrency Operating System Concepts

Single vs. multiprocessor In a single-processor architecture, multithreading generally occurs by time-division multiplexing (as in multitasking): the CPU generally moves between each thread so quickly as to create an illusion of parallelism, but in reality only one thread is running at all time On a multiprocessor or multi-core system, the threads or tasks will generally run at the same time, with each processor or core running a particular thread or task. Operating System Concepts

User and Kernel Threads Support for threads may be provided at either the user level, for user threads, or by the kernel, for kernel threads. Operating System Concepts

Operating System Concepts User Threads Thread management done by user-level threads library Supported and managed above the kernel and are implemented by a thread library at the user level. The library provides support for thread creation, scheduling, and management with no support from the kernel. The kernel is unaware of user-level threads, all thread creation and scheduling are done in user space without the need for kernel intervention. User-level threads are generally fast to create and manage. Operating System Concepts

Operating System Concepts User Threads (Cont.) Drawbacks: if the kernel is single-threaded, then any user-level thread performing a blocking system call will cause the entire process to block, even if other threads are available to run within the application. Examples: POSIX Pthreads Mach C-threads Solaris 2 UI-threads Operating System Concepts

Operating System Concepts Kernel Threads Supported and managed by the Kernel (OS) The kernel performs thread creation, scheduling, and management in kernel space. Kernel threads are generally slower to create and manage than are user threads. If a thread performs a blocking system call, the kernel can schedule another thread in the application for execution. Also, in a multiprocessor environment, the kernel can schedule threads on different processors. Examples - Windows 95/98/NT/2000 - Solaris 2 - Tru64 UNIX - BeOS Operating System Concepts

Multithreading Models Many-to-One (User-level threading) One-to-One (Kernel-level threading) Many-to-Many (Hybrid threading) Operating System Concepts

Operating System Concepts Many-to-One Many user-level threads mapped to single kernel thread It is efficient because thread management is done in user space Shortcoming: The entire process will block if a thread makes a blocking system call Only one thread can access the kernel at a time, therefore multiple threads are unable to run in parallel on multiprocessors Used on systems that do not support kernel threads. Operating System Concepts

Operating System Concepts Many-to-One Model Operating System Concepts

Operating System Concepts One-to-One Each user-level thread maps to kernel thread. Allow more concurrency than many-to-one by allowing another thread to run when a thread makes a blocking system call. It also allows multiple threads to run in parallel on multiprocessors. Shortcoming: The overhead of creating kernel threads can burden the performance of an application Examples - Windows 95/98/NT/2000 - OS/2 Operating System Concepts

Operating System Concepts One-to-one Model Operating System Concepts

Many-to-Many Model (N : M) Multiplexes many user-level threads to a smaller or equal number of kernel threads Allows the operating system to create a sufficient number of kernel threads. Suffers from neither of the shortcomings of the other two approaches (1:1 and 1:N) Developers can create as many user threads as necessary And the corresponding kernel threads can run in parallel on a multiprocessor. The kernel can schedule another thread for execution, when a thread performs a blocking system call. Operating System Concepts

Many-to-Many Model (cont.) Examples: Solaris 2 IRIX HP-UX Tru64 UNIX Operating System Concepts

Operating System Concepts Many-to-Many Model Operating System Concepts