Computer Science Lecture 6, page 1 CS677: Distributed OS Processes and Threads Processes and their scheduling Multiprocessor scheduling Threads Distributed.

Slides:



Advertisements
Similar presentations
Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Advertisements

Computer Science Lecture 6, page 1 CS677: Distributed OS Processes and Threads Processes and their scheduling Multiprocessor scheduling Threads Distributed.
Chapter 5 Threads os5.
Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 5: Threads 9/29/03+ Overview Benefits User and Kernel Threads Multithreading.
Threads Clients Servers Code Migration Software Agents Summary
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
3.5 Interprocess Communication
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
Threads & Scheduling What are 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.
1 Process States (1) Possible process states –running –blocked –ready Transitions between states shown.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Threads, Thread management & Resource Management.
Operating System Concepts Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Scheduling Basic scheduling policies, for OS schedulers (threads, tasks, processes) or thread library schedulers Review of Context Switching overheads.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
OPERATING SYSTEM SUPPORT DISTRIBUTED SYSTEMS CHAPTER 6 Lawrence Heyman July 8, 2002.
CS333 Intro to Operating Systems Jonathan Walpole.
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 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Department of Computer Science and Software Engineering
Operating Systems: Internals and Design Principles
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Distributed (Operating) Systems -Processes and Threads-
Processes & Threads Introduction to Operating Systems: Module 5.
1 OS Review Processes and Threads Chi Zhang
Threads-Process Interaction. CONTENTS  Threads  Process interaction.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-2: Threads Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Processes Chapter 3. Processes in Distributed Systems Processes and threads –Introduction to threads –Distinction between threads and processes Threads.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
CS 6560: Operating Systems Design
Processes and Threads Processes and their scheduling
OPERATING SYSTEMS CS3502 Fall 2017
CS399 New Beginnings Jonathan Walpole.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 4 Threads.
Threads & multithreading
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 4: Threads.
ICS 143 Principles of Operating Systems
Threads Chapter 4.
Multiprocessor and Real-Time Scheduling
Presentation transcript:

Computer Science Lecture 6, page 1 CS677: Distributed OS Processes and Threads Processes and their scheduling Multiprocessor scheduling Threads Distributed Scheduling/migration

Computer Science Lecture 6, page 2 CS677: Distributed OS 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

Computer Science Lecture 6, page 3 CS677: Distributed OS 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 -  x -(1-p) e -  x E[X] = p/  p)/ 

Computer Science Lecture 6, page 4 CS677: Distributed OS 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

Computer Science Lecture 6, page 5 CS677: Distributed OS 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

Computer Science Lecture 6, page 6 CS677: Distributed OS Threads Each thread has its own stack, PC, registers –Share address space, files,…

Computer Science Lecture 6, page 7 CS677: Distributed OS Why use Threads? Large multiprocessors need many computing entities (one per CPU) 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

Computer Science Lecture 6, page 8 CS677: Distributed OS Why Threads? Single threaded process: blocking system calls, no parallelism Finite-state machine [event-based]: non-blocking with parallelism 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

Computer Science Lecture 6, page 9 CS677: Distributed OS 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…

Computer Science Lecture 6, page 10 CS677: Distributed OS Multi-threaded Server Example Apache web server: pool of pre-spawned worker threads –Dispatcher thread waits for requests –For each request, choose an idle worker thread –Worker thread uses blocking system calls to service web request

Computer Science Lecture 6, page 11 CS677: Distributed OS 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

Computer Science Lecture 6, page 12 CS677: Distributed OS 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

Computer Science Lecture 6, page 13 CS677: Distributed OS 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]

Computer Science Lecture 6, page 14 CS677: Distributed OS User-level threads

Computer Science Lecture 6, page 15 CS677: Distributed OS Kernel-level threads Kernel aware of the presence of threads –Better scheduling decisions, more expensive –Better for multiprocessors, more overheads for uniprocessors

Computer Science Lecture 6, page 16 CS677: Distributed OS Light-weight Processes Several LWPs per heave-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

Computer Science Lecture 6, page 17 CS677: Distributed OS LWP Example

Computer Science Lecture 6, page 18 CS677: Distributed OS 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

Computer Science Lecture 6, page 19 CS677: Distributed OS Course Project Part 1: Peer-to-peer file sharing with centralized index Foo.avi: Node1 Bar.c: Node 1 Foo.avi: Node 2 Mypic.gif: Node 3 Indexing server Peer 1 Peer 2 Peer 3 1: Register (node 1,foo.avi) 2: Lookup(foo.avi) 3: Node1, node2 4: Download (foo.avi)

Computer Science Lecture 6, page 20 CS677: Distributed OS Course Project Two entities –Central indexing server List of all files at peers –Peer (both client and server) [client] Search for a file at the indexing server Download file from a peer, update indexing server [server] listen for download requests and service –Provide concurrency at the central indexing server and peer Feel free to use any prog language and any mechanism (threads, RPC, RMI, sockets, semaphores…)