Operating Systems: Internals and Design Principles. Chapter 4 Threads Seventh Edition By William Stallings

Similar documents
For use by students enrolled in #71251 CSE430 Fall 2012 at Arizona State University. Do not use if not enrolled.

ECE519 Advanced Operating Systems

Chapter 4 Threads, SMP, and

2017 Pearson Educa2on, Inc., Hoboken, NJ. All rights reserved.

Chapter 3 Process Description and Control

Operating System. Chapter 4. Threads. Lynn Choi School of Electrical Engineering

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

Threads Chapter 5 1 Chapter 5

Process Characteristics

Process Characteristics. Threads Chapter 4. Process Characteristics. Multithreading vs. Single threading

Threads Chapter 4. Reading: 4.1,4.4, 4.5

Threads, SMP, and Microkernels

Threads. CS3026 Operating Systems Lecture 06

Operating System 4 THREADS, SMP AND MICROKERNELS

Threads, SMP, and Microkernels. Chapter 4

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

Processes, Threads, SMP, and Microkernels

Multithreading. Reading: Silberschatz chapter 5 Additional Reading: Stallings chapter 4

CSE 306/506 Operating Systems Threads. YoungMin Kwon

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

operating system Spring 2017 Prof.Dr. Hasan Balik Student Name : Walid.W. Ramadan mansour Student ID :

Threads. Thread Concept Multithreading Models User & Kernel Threads Pthreads Threads in Solaris, Linux, Windows. 2/13/11 CSE325 - Threads 1

Process Description and Control

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

UNIT 3. PROCESS MANAGEMENT

Operating System Overview. Chapter 2

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

OPERATING SYSTEM. Chapter 4: Threads

Chapter 4: Threads. Chapter 4: Threads

4. Concurrency via Threads

Sistemas Operacionais I. Valeria Menezes Bastos

Thread Concept. Thread. No. 3. Multiple single-threaded Process. One single-threaded Process. Process vs. Thread. One multi-threaded Process

IT 540 Operating Systems ECE519 Advanced Operating Systems

Operating Systems 2 nd semester 2016/2017. Chapter 4: Threads

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Operating Systems Overview. Chapter 2

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Announcement. Exercise #2 will be out today. Due date is next Monday

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne

Chapter 5: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

Operating System. Operating System Overview. Layers of Computer System. Operating System Objectives. Services Provided by the Operating System

Operating System Overview. Operating System

Processes and Threads. Processes: Review

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING

Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors

Learning Outcomes. Processes and Threads. Major Requirements of an Operating System. Processes and Threads

Operating Systems. Lecture 4. Nachos Appetizer

Operating Systems. Chapter 4 Threads. Lei Duan

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Chapter 4: Multi-Threaded Programming

Processes and Threads

Processes and Threads

Chapter 5: Threads. Outline

Agenda. Threads. Single and Multi-threaded Processes. What is Thread. CSCI 444/544 Operating Systems Fall 2008

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

Lecture Contents. 1. Overview. 2. Multithreading Models 3. Examples of Thread Libraries 4. Summary

SMD149 - Operating Systems

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

Process Description and Control

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads


Chapter 4: Threads. Operating System Concepts 9 th Edition

Chapter 4: Threads. Operating System Concepts 9 th Edition

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

Chapter 4: Multithreaded Programming

CSE 153 Design of Operating Systems Fall 2018

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

DISTRIBUTED COMPUTER SYSTEMS

Chapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition,

3.1 Introduction. Computers perform operations concurrently

Processes. CS3026 Operating Systems Lecture 05

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011

Multithreaded Programming

Yi Shi Fall 2017 Xi an Jiaotong University

Chapter 6 Concurrency: Deadlock and Starvation

Operating Systems: Internals and Design Principles. Chapter 2 Operating System Overview Seventh Edition By William Stallings

Concurrency, Thread. Dongkun Shin, SKKU

Chapter 4: Threads. Chapter 4: Threads

CHAPTER 2: PROCESS MANAGEMENT

4.8 Summary. Practice Exercises

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

Process Description and Control

CS420: Operating Systems

Chapter 4: Multithreaded Programming

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Process Description and Control. Chapter 3

CISC2200 Threads Spring 2015

CSE 4/521 Introduction to Operating Systems. Lecture 29 Windows 7 (History, Design Principles, System Components, Programmer Interface) Summer 2018

OPERATING SYSTEM : RBMCQ0402. Third RavishBegusarai.

POSIX Threads: a first step toward parallel programming. George Bosilca

POSIX Threads Programming

CSCE 313: Intro to Computer Systems

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Transcription:

Operating Systems: Internals and Design Principles Chapter 4 Threads Seventh Edition By William Stallings

Operating Systems: Internals and Design Principles The basic idea is that the several components in any complex system will perform particular subfunctions that contribute to the overall function. THE SCIENCES OF THE ARTIFICIAL, Herbert Simon

Processes and Threads Processes have two characteristics: Resource Ownership Process includes a virtual address space to hold the process image the OS performs a protection function to prevent unwanted interference between processes with respect to resources Scheduling/Execution Follows an execution path that may be interleaved with other processes a process has an execution state (Running, Ready, etc.) and a dispatching priority and is scheduled and dispatched by the OS

Processes and Threads The unit of dispatching is referred to as a thread or lightweight process The unit of resource ownership is referred to as a process or task Multithreading - The ability of an OS to support multiple, concurrent paths of execution within a single process

Single Threaded Approaches A single thread of execution per process, in which the concept of a thread is not recognized, is referred to as a single-threaded approach MS-DOS is an example

Multithreaded Approaches The right half of Figure 4.1 depicts multithreaded approaches A Java run-time environment is an example of a system of one process with multiple threads

Processes The unit or resource allocation and a unit of protection A virtual address space that holds the process image Protected access to: processors other processes files I/O resources

One or More Threads in a Process

Threads vs. Processes

Benefits of Threads

Thread Use in a Single-User System Foreground and background work Asynchronous processing Speed of execution Modular program structure

In an OS that supports threads, scheduling and dispatching is done on a thread basis suspending a process involves suspending all threads of the process termination of a process terminates all threads within the process

The key states for a thread are: Running Ready Blocked Thread operations associated with a change in thread state are: Spawn Block Unblock Finish

RPC Using Single Thread

RPC Using One Thread per Server

Multithreading on a Uniprocessor

Thread Synchronization It is necessary to synchronize the activities of the various threads all threads of a process share the same address space and other resources any alteration of a resource by one thread affects the other threads in the same process

Types of Threads

User-Level Threads (ULTs) All thread management is done by the application The kernel is not aware of the existence of threads

Relationships Between ULT States and Process States Figure 4.6 Examples of the Relationships between User-Level Thread States and Process States

Disadvantages of ULTs In a typical OS many system calls are blocking as a result, when a ULT executes a system call, not only is that thread blocked, but all of the threads within the process are blocked In a pure ULT strategy, a multithreaded application cannot take advantage of multiprocessing

Overcoming ULT Disadvantages

Kernel-Level Threads (KLTs) Thread management is done by the kernel no thread management is done by the application Windows is an example of this approach

Advantages of KLTs The kernel can simultaneously schedule multiple threads from the same process on multiple processors If one thread in a process is blocked, the kernel can schedule another thread of the same process Kernel routines can be multithreaded

Disadvantage of KLTs The transfer of control from one thread to another within the same process requires a mode switch to the kernel

Combined Approaches Thread creation is done in the user space Bulk of scheduling and synchronization of threads is by the application Solaris is an example

Relationship Between Threads and Processes Table 4.2 Relationship between Threads and Processes

Performance Effect of Multiple Cores Figure 4.7 (a) Figure 4.7 (b)

Database Workloads on Multiple-Processor Hardware Figure 4.8 Scaling of Database Workloads on Multiple Processor Hardware

Applications That Benefit Multithreaded native applications characterized by having a small number of highly threaded processes Multiprocess applications characterized by the presence of many single-threaded processes Java applications Multiinstance applications multiple instances of the application in parallel

Relationship Between Process and Resource Figure 4.10 A Windows Process and Its Resources

Process and Thread Objects Windows makes use of two types of process-related objects:

Windows Process and Thread Objects

Windows Process Object Attributes Table 4.3 Windows Process Object Attributes

Windows Thread Object Attributes Table 4.4 Windows Thread Object Attributes

Multithreaded Process

Thread States Figure 4.12 Windows Thread States

Symmetric Multiprocessing Support (SMP)

Solaris Process - makes use of four thread-related concepts:

Processes and Threads in Solaris Figure 4.13 Processes and Threads in Solaris [MCDO07]

Traditional Unix vs Solaris Figure 4.14 Process Structure in Traditional UNIX and Solaris [LEWI96]

A Lightweight Process (LWP) Data Structure Includes: An LWP identifier The priority of this LWP A signal mask Saved values of user-level registers The kernel stack for this LWP Resource usage and profiling data Pointer to the corresponding kernel thread Pointer to the process structure

Solaris Thread States Figure 4.15 Solaris Thread States

Interrupts as Threads Most operating systems contain two fundamental forms of concurrent activity:

Solaris Solution Solaris employs a set of kernel threads to handle interrupts an interrupt thread has its own identifier, priority, context, and stack the kernel controls access to data structures and synchronizes among interrupt threads using mutual exclusion primitives interrupt threads are assigned higher priorities than all other types of kernel threads

Linux Tasks

Linux Process/Thread Model Figure 4.16 Linux Process/Thread Model

Linux Threads

Linux Clone () Flags

Mac OS X Grand Central Dispatch (GCD) Provides a pool of available threads Designers can designate portions of applications, called blocks, that can be dispatched independently and run concurrently Concurrency is based on the number of cores available and the thread capacity of the system

A simple extension to a language A block defines a self-contained unit of work Enables the programmer to encapsulate complex functions Scheduled and dispatched by queues Dispatched on a first-in-first-out basis Can be associated with an event source, such as a timer, network socket, or file descriptor

Summary User-level threads created and managed by a threads library that runs in the user space of a process a mode switch is not required to switch from one thread to another only a single user-level thread within a process can execute at a time if one thread blocks, the entire process is blocked Kernel-level threads threads within a process that are maintained by the kernel a mode switch is required to switch from one thread to another multiple threads within the same process can execute in parallel on a multiprocessor blocking of a thread does not block the entire process Process/related to resource ownership Thread/related to program execution