Last Class: CPU Scheduling. Pre-emptive versus non-preemptive schedulers Goals for Scheduling: CS377: Operating Systems.

Similar documents
Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Announcements/Reminders

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

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

CS 450 Operating System Week 4 Lecture Notes

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

Chapter 4: Threads. Chapter 4: Threads

Chapter 4: Multi-Threaded Programming

Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads. Operating System Concepts

Chapter 4: Threads. Operating System Concepts with Java 8 th Edition

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

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

CS307: Operating Systems

Chapter 4: Multithreaded

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

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

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

CS420: Operating Systems

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

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

Last Class: Processes

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

Multithreaded Programming

Processes and Threads. Processes: Review

Processes and Threads

Distributed Systems Operation System Support

CS370 Operating Systems

OPERATING SYSTEM. Chapter 4: Threads

Chapter 5: Threads. Outline

Threads. CS3026 Operating Systems Lecture 06

Processes and Threads

CSE 120 Principles of Operating Systems

CSE 4/521 Introduction to 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

CS370 Operating Systems

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

Yi Shi Fall 2017 Xi an Jiaotong University

Chapter 3 Process Description and Control

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

Threads and Too Much Milk! CS439: Principles of Computer Systems January 31, 2018

Process Description and Control

COP 4610: Introduction to Operating Systems (Spring 2015) Chapter 4: Threads. Zhi Wang Florida State University

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

Chapter 4: Threads. Chapter 4: Threads

CSMC 412. Operating Systems Prof. Ashok K Agrawala Ashok Agrawala Set 4. September 2006 CMSC 412 Set 4

Chapter 4: Threads. Operating System Concepts 8 th Edition,

Chapter 5: Threads. Single and Multithreaded Processes

Chapter 4: Multithreaded Programming

Threads. studykorner.org

CS370 Operating Systems

Threads Chapter 5 1 Chapter 5

Advanced Operating Systems (CS 202) Scheduling (1)

Operating Systems Prof. Ashok K Agrawala

Processes & Threads. Recap of the Last Class. Microkernel System Architecture. Layered Structure

Threads and Too Much Milk! CS439: Principles of Computer Systems February 6, 2019

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

CISC2200 Threads Spring 2015

CHAPTER 2: PROCESS MANAGEMENT

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Lecture 2 Process Management

Threads. Still Chapter 2 (Based on Silberchatz s text and Nachos Roadmap.) 3/9/2003 B.Ramamurthy 1

Process- Concept &Process Scheduling OPERATING SYSTEMS

Definition Multithreading Models Threading Issues Pthreads (Unix)

Chapter 5: CPU Scheduling

CSE 120 Principles of Operating Systems

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

CPSC 341 OS & Networks. Threads. Dr. Yingwu Zhu

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

Lecture 4 Threads. (chapter 4)

Threads Implementation. Jo, Heeseung

Concurrency, Thread. Dongkun Shin, SKKU

Threads. Today. Next time. Why threads? Thread model & implementation. CPU Scheduling

Page 1. Analogy: Problems: Operating Systems Lecture 7. Operating Systems Lecture 7

Supplementary Materials on Multilevel Feedback Queue

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

Notes. CS 537 Lecture 5 Threads and Cooperation. Questions answered in this lecture: What s in a process?

Chapter 4: Threads. Operating System Concepts 9 th Edition

CS Lecture 3! Threads! George Mason University! Spring 2010!

SMD149 - Operating Systems

CS 3305 Intro to Threads. Lecture 6

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

Chapter 5: CPU Scheduling

Chapter 3: Processes. Operating System Concepts 8th Edition

CPSC 341 OS & Networks. Introduction. Dr. Yingwu Zhu

CSI3131 Final Exam Review

CS 318 Principles of Operating Systems

Operating Systems. Figure: Process States. 1 P a g e

Chapter 5: CPU Scheduling. Operating System Concepts Essentials 8 th Edition

Lecture 4: Threads; weaving control flow

CSE 120 Principles of Operating Systems

Threads. To do. Why threads? Thread model & implementation. q q q. q Next time: Synchronization

CSE 4/521 Introduction to Operating Systems

Interoperation of tasks

Copyright Notice David A. Solomon and Mark Russinovich

Chapter 4 Multithreaded Programming

Chapter 4: Threads. Operating System Concepts 9 th Edition

Process and Its Image An operating system executes a variety of programs: A program that browses the Web A program that serves Web requests

Chapter 2 Processes and Threads

Transcription:

Last Class: CPU Scheduling Pre-emptive versus non-preemptive schedulers Goals for Scheduling: Minimize average response time Maximize throughput Share CPU equally Other goals? Scheduling Algorithms: Selecting a scheduling algorithm is a policy decision - consider tradeoffs FSCS Round-robin SJF/SRTF MLFQ Lottery scheduler Lecture 6, page 1 Today: Threads What are threads? Where should we implement threads? In the kernel? In a user level threads package? How should we schedule threads (or processes) onto the CPU? Lecture 6, page 2

Processes versus Threads A process defines the address space, text, resources, etc., A thread defines a single sequential execution stream within a process (PC, stack, registers). Threads extract the thread of control information from the process Threads are bound to a single process. Each process may have multiple threads of control within it. The address space of a process is shared among all its threads No system calls are required to cooperate among threads Simpler than message passing and shared-memory Lecture 6, page 3 Single and Multithreaded Processes Lecture 6, page 4

Classifying Threaded Systems Operating Systems can support one or many address spaces, and one or many threads per address space. Lecture 6, page 5 Example Threaded Program Forking a thread can be a system call to the kernel, or a procedure call to a thread library (user code). Lecture 6, page 6

Kernel Threads A kernel thread, also known as a lightweight process, is a thread that the operating system knows about. Switching between kernel threads of the same process requires a small context switch. The values of registers, program counter, and stack pointer must be changed. Memory management information does not need to be changed since the threads share an address space. The kernel must manage and schedule threads (as well as processes), but it can use the same process scheduling algorithms. èswitching between kernel threads is slightly faster than switching between processes. Lecture 6, page 7 User-Level Threads A user-level thread is a thread that the OS does not know about. The OS only knows about the process containing the threads. The OS only schedules the process, not the threads within the process. The programmer uses a thread library to manage threads (create and delete them, synchronize them, and schedule them). Lecture 6, page 8

User-Level Threads Lecture 6, page 9 User-Level Threads: Advantages There is no context switch involved when switching threads. User-level thread scheduling is more flexible A user-level code can define a problem dependent thread scheduling policy. Each process might use a different scheduling algorithm for its own threads. A thread can voluntarily give up the processor by telling the scheduler it will yield to other threads. User-level threads do not require system calls to create them or context switches to move between them thread management calls are library calls and much faster than system calls made by kernel threads è User-level threads are typically much faster than kernel threads Lecture 6, page 10

User-Level Threads: Disadvantages Since the OS does not know about the existence of the user-level threads, it may make poor scheduling decisions: It might run a process that only has idle threads. If a user-level thread is waiting for I/O, the entire process will wait. Solving this problem requires communication between the kernel and the user-level thread manager. Since the OS just knows about the process, it schedules the process the same way as other processes, regardless of the number of user threads. For kernel threads, the more threads a process creates, the more time slices the OS will dedicate to it. Lecture 6, page 11 Example: Kernel and User-Level Threads in Solaris Lecture 6, page 12

Threading Models Many-to-one, one-to-one, many-to-many and two-level Lecture 6, page 13 Two-level Model Lecture 6, page 14

Thread Libraries Thread library provides programmer with API for creating and managing threads Two primary ways of implementing Library entirely in user space Kernel-level library supported by the OS Lecture 6, page 15 Pthreads May be provided either as user-level or kernel-level A POSIX standard (IEEE 1003.1c) 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) WIN32 Threads: Similar to Posix, but for Windows Lecture 6, page 16

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 Lecture 6, page 17 Examples Pthreads: pthread_attr_init(&attr); /* set default attributes */ pthread_create(&tid, &attr, sum, &param); Win32 threads ThreadHandle = CreateThread(NULL, 0, Sum, &Param, 0, &ThreadID); Java Threads: Sum sumobject = new Sum(); Thread t = new Thread(new Summation(param, SumObject)); t.start(); // start the thread Lecture 6, page 18

Summary Thread: a single execution stream within a process Switching between user-level threads is faster than between kernel threads since a context switch is not required. User-level threads may result in the kernel making poor scheduling decisions, resulting in slower process execution than if kernel threads were used. Many scheduling algorithms exist. Selecting an algorithm is a policy decision and should be based on characteristics of processes being run and goals of operating system (minimize response time, maximize throughput,...). Lecture 6, page 19