Processes and Threads. Processes: Review

Similar documents
Chapter 2 Processes and Threads

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

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

Comp 310 Computer Systems and Organization

Announcements/Reminders

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

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

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

Lecture 2 Process Management

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

Chapter 3 Process Description and Control

Last Class: Processes

Chapter 5: Threads. Outline

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

Operating Systems. Lecture 4. Nachos Appetizer

8: Scheduling. Scheduling. Mark Handley

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

CHAPTER 2: PROCESS MANAGEMENT

Announcements. Program #1. Program #0. Reading. Is due at 9:00 AM on Thursday. Re-grade requests are due by Monday at 11:59:59 PM.

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

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

Today s class. Scheduling. Informationsteknologi. Tuesday, October 9, 2007 Computer Systems/Operating Systems - Class 14 1

SMD149 - Operating Systems

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

TDIU25: Operating Systems II. Processes, Threads and Scheduling

CS418 Operating Systems

Processes and Threads

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

Chapter 5: CPU Scheduling

Chapter 4: Threads. Chapter 4: Threads

CSE 4/521 Introduction to Operating Systems

CS370 Operating Systems

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Chapter 5: CPU Scheduling

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

Uniprocessor Scheduling

Process- Concept &Process Scheduling OPERATING SYSTEMS

Chapter 4: Multithreaded Programming


Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

Uniprocessor Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Three level scheduling

Chapter 4: Multi-Threaded Programming

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CS450/550 Operating Systems

CSCE 313: Intro to Computer Systems

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

OPERATING SYSTEM. Chapter 4: Threads

PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug

CPU Scheduling. Schedulers. CPSC 313: Intro to Computer Systems. Intro to Scheduling. Schedulers in the OS

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

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

Chapter 5 CPU scheduling

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

Chapter 9 Uniprocessor Scheduling

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread

CS 450 Operating System Week 4 Lecture Notes

OS Assignment II. The process of executing multiple threads simultaneously is known as multithreading.

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

CSE 153 Design of Operating Systems

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

Advanced Operating Systems (CS 202) Scheduling (1)

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

Processes and Threads

CS370 Operating Systems

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

Department of Computer applications. [Part I: Medium Answer Type Questions]

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

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

LECTURE 3:CPU SCHEDULING

Threads, SMP, and Microkernels

4. Concurrency via Threads

CS370 Operating Systems

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

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

Process Description and Control

CS450/550 Operating Systems

OPERATING SYSTEMS. COMS W1001 Introduction to Information Science. Boyi Xie

Chapter 6: CPU Scheduling

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Chapter 5: CPU Scheduling

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

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

CSc33200: Operating Systems, CS-CCNY, Fall 2003 Jinzhong Niu December 10, Review

Module 20: Multi-core Computing Multi-processor Scheduling Lecture 39: Multi-processor Scheduling. The Lecture Contains: User Control.

Threads. CS3026 Operating Systems Lecture 06

Motivation of Threads. Preview. Motivation of Threads. Motivation of Threads. Motivation of Threads. Motivation of Threads 9/12/2018.

Operating Systems. Lecture Process Scheduling. Golestan University. Hossein Momeni

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

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

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

Scheduling of processes

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Yi Shi Fall 2017 Xi an Jiaotong University

CMPSCI 377: Operating Systems Exam 1: Processes, Threads, CPU Scheduling and Synchronization. October 9, 2002

CSE 120 Principles of Operating Systems

Uniprocessor Scheduling. Aim of Scheduling

Uniprocessor Scheduling. Aim of Scheduling. Types of Scheduling. Long-Term Scheduling. Chapter 9. Response time Throughput Processor efficiency

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

Process Concept Process in Memory Process State new running waiting ready terminated Diagram of Process State

Transcription:

Processes and Threads Processes and their scheduling Threads and scheduling Multiprocessor scheduling Distributed Scheduling/migration Lecture 3, page 1 Processes: Review Multiprogramming versus multiprocessing Kernel data structure: process control block (PCB) Each process has an address space Contains code, global and local variables.. Process state transitions Uniprocessor scheduling algorithms Round-robin, shortest job first, FIFO, lottery scheduling, EDF Performance metrics: throughput, CPU utilization, turnaround time, response time, fairness Lecture 3, page 2

Process Behavior Processes: alternate between CPU and I/O CPU bursts Most bursts are short, a few are very long (high variance) Modeled using hyperexponential behavior If X is an exponential r.v. Pr [ X <= x] = 1 e -µx E[X] = 1/µ If X is a hyperexponential r.v. Pr [X <= x] = 1 p e -µ1x -(1-p) e -µ2x E[X] = p/ µ1 + (1 p)/ µ2 Lecture 3, page 3 Process Scheduling Priority queues: multiples queues, each with a different priority Use strict priority scheduling Example: page swapper, kernel tasks, real-time tasks, user tasks Multi-level feedback queue Multiple queues with priority Processes dynamically move from one queue to another Depending on priority/cpu characteristics Gives higher priority to I/O bound or interactive tasks Lower priority to CPU bound tasks Round robin at each level Lecture 3, page 4

Processes and Threads Traditional process One thread of control through a large, potentially sparse address space Address space may be shared with other processes (shared mem) Collection of systems resources (files, semaphores) Thread (light weight process) A flow of control through an address space Each address space can have multiple concurrent control flows Each thread has access to entire address space Potentially parallel execution, minimal state (low overheads) May need synchronization to control access to shared variables Lecture 3, page 5 Threads Each thread has its own stack, PC, registers Share address space, files, Lecture 3, page 6

Why use Threads? Large multiprocessors/multi-core systems need many computing entities (one per CPU or core ) Switching between processes incurs high overhead With threads, an application can avoid per-process overheads Thread creation, deletion, switching cheaper than processes Threads have full access to address space (easy sharing) Threads can execute in parallel on multiprocessors Lecture 3, page 7 Why Threads? Single threaded process: blocking system calls, no concurrency/parallelism Finite-state machine [event-based]: non-blocking with concurrency Multi-threaded process: blocking system calls with parallelism Threads retain the idea of sequential processes with blocking system calls, and yet achieve parallelism Software engineering perspective Applications are easier to structure as a collection of threads Each thread performs several [mostly independent] tasks Lecture 3, page 8

Multi-threaded Clients Example : Web Browsers Browsers such as IE are multi-threaded Such browsers can display data before entire document is downloaded: performs multiple simultaneous tasks Fetch main HTML page, activate separate threads for other parts Each thread sets up a separate connection with the server Uses blocking calls Each part (gif image) fetched separately and in parallel Advantage: connections can be setup to different sources Ad server, image server, web server Lecture 3, page 9 Multi-threaded Server Example Apache web server: pool of pre-spawned worker threads Dispatcher thread waits for requests ( master slave architecture) For each request, choose an idle worker thread Worker thread uses blocking system calls to service web request Lecture 3, page 10

Thread Management Creation and deletion of threads Static versus dynamic Critical sections Synchronization primitives: blocking, spin-lock (busy-wait) Condition variables Global thread variables Kernel versus user-level threads Lecture 3, page 11 User-level versus kernel threads Key issues: Cost of thread management More efficient in user space Ease of scheduling Flexibility: many parallel programming models and schedulers Process blocking a potential problem Lecture 3, page 12

User-level Threads Threads managed by a threads library Kernel is unaware of presence of threads Advantages: No kernel modifications needed to support threads Efficient: creation/deletion/switches don t need system calls Flexibility in scheduling: library can use different scheduling algorithms, can be application dependent Disadvantages Need to avoid blocking system calls [all threads block] Threads compete for one another Does not take advantage of multiprocessors [no real parallelism] Lecture 3, page 13 User-level threads Lecture 3, page 14

Kernel-level threads Kernel aware of the presence of threads Better scheduling decisions, more expensive Better for multiprocessors, more overheads for uniprocessors Lecture 3, page 15 Scheduler Activation User-level threads: scheduling both at user and kernel levels user thread system call: process blocks kernel may context switch thread during important tasks Need mechanism for passing information back and forth Scheduler activation: OS mechanism for user level threads Notifies user-level library of kernel events Provides data structures for saving thread context Kernel makes up-calls : CPU available, I/O is done etc. Library informs kernel: create/delete threads Performance of user-level threads with behavior of kernel threads Lecture 3, page 16

Light-weight Processes Several LWPs per heavy-weight process User-level threads package Create/destroy threads and synchronization primitives Multithreaded applications create multiple threads, assign threads to LWPs (one-one, many-one, many-many) Each LWP, when scheduled, searches for a runnable thread [two-level scheduling] Shared thread table: no kernel support needed When a LWP thread block on system call, switch to kernel mode and OS context switches to another LWP Lecture 3, page 17 LWP Example Lecture 3, page 18

Thread Packages Posix Threads (pthreads) Widely used threads package Conforms to the Posix standard Sample calls: pthread_create, Typical used in C/C++ applications Can be implemented as user-level or kernel-level or via LWPs Java Threads Native thread support built into the language Threads are scheduled by the JVM Lecture 3, page 19