Computer Science 162 Discussion Section Week 2. Agenda Recap “What is an OS?” and Why? Process vs. Thread “THE” System.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
Introduction CSCI 444/544 Operating Systems Fall 2008.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Introduction to Operating Systems CS-2301 B-term Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials.
Review: Chapters 1 – Chapter 1: OS is a layer between user and hardware to make life easier for user and use hardware efficiently Control program.
CMPT 300: Operating Systems I Dr. Mohamed Hefeeda
CS533 Concepts of Operating Systems Class 5 Integrated Task and Stack Management.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Dr. Mohamed Hefeeda.
1 CS 333 Introduction to Operating Systems Class 2 – OS-Related Hardware & Software The Process Concept Jonathan Walpole Computer Science Portland State.
Threads vs. Processes April 7, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
1/28/2004CSCI 315 Operating Systems Design1 Operating System Structures & Processes Notice: The slides for this lecture have been largely based on those.
CS533 Concepts of Operating Systems Class 7 Integrated Task and Stack Management.
CS533 - Concepts of Operating Systems
Operating Systems CS208. What is Operating System? It is a program. It is the first piece of software to run after the system boots. It coordinates the.
1 Chapter 4 Threads Threads: Resource ownership and execution.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
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.
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.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
CS 162 Discussion Section Week 1 (9/9 – 9/13) 1. Who am I? Kevin Klues Office Hours:
Introduction and Overview Questions answered in this lecture: What is an operating system? How have operating systems evolved? Why study operating systems?
Threads, Thread management & Resource Management.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Threads and Processes.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Thread Scheduling.
Chapter 7 Operating Systems. Define the purpose and functions of an operating system. Understand the components of an operating system. Understand the.
Computers Operating System Essentials. Operating Systems PROGRAM HARDWARE OPERATING SYSTEM.
Operating Systems and Systems Programming CS162 Teaching Staff.
Scheduling Lecture 6. What is Scheduling? An O/S often has many pending tasks. –Threads, async callbacks, device input. The order may matter. –Policy,
OPERATING SYSTEM SUPPORT DISTRIBUTED SYSTEMS CHAPTER 6 Lawrence Heyman July 8, 2002.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
CS 162 Discussion Section Week 2. Who am I? Haoyuan (HY) Li Office Hours: 1pm-3pm
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Introduction to Operating Systems and Concurrency.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
The Structure of the “THE”- Multiprogramming System Edsger W. Dijkstra Presented by: Jin Li.
Department of Computer Science and Software Engineering
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Distributed (Operating) Systems -Processes and Threads-
1 OS Review Processes and Threads Chi Zhang
12/2/091 What is an Operating System Andy Konwinski CS61CL Dec 2, 2009 Lecture 13 UCB CS61CL F09 Lec 13.
Concepts and Structures. Main difficulties with OS design synchronization ensure a program waiting for an I/O device receives the signal mutual exclusion.
Major OS Components CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
CS 162 Discussion Section Week 2. Who am I? Prashanth Mohan Office Hours: 11-12pm Tu W at.
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Processes and threads.
Processes and Threads Processes and their scheduling
Threads & multithreading
Operating Systems and Systems Programming
GEOMATIKA UNIVERSITY COLLEGE CHAPTER 2 OPERATING SYSTEM PRINCIPLES
Chapter 15, Exploring the Digital Domain
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads and Concurrency
Threads Chapter 4.
CSE 451: Operating Systems Winter 2003 Lecture 1 Course Introduction
CSE 451: Operating Systems Autumn 2003 Lecture 1 Course Introduction
CS703 – Advanced Operating Systems
Presentation transcript:

Computer Science 162 Discussion Section Week 2

Agenda Recap “What is an OS?” and Why? Process vs. Thread “THE” System

Note: Many slides are modifications of slides from Matei Zaharia Who referenced slides from Steve Gribble, Ed Lazowska, Hank Levy, and John Zahorian

Why do we want an OS? Isolation – Fault: “if my program crashes yours shouldn’t” – Performance: “if my program starts to do some massive computation, it shouldn’t starve yours from running” Mediation (multiplexing/sharing + protection) – Manage the sharing of hardware resources (CPU, NIC, RAM, disk, keyboard, sound card, etc), Abstractions and Primitives – Set of constructs and well-defined interfaces to simplify application development: “all the code you didn’t write” in order to implement your application Because hardware changes faster than applications! Because some concepts are useful across applications

Why bother with an OS? User benefits – Efficiency (cost and performance) share one computer across many users concurrent execution of multiple programs – Safety OS protects programs from each other OS fairly multiplexes resources across programs Application benefits – Simplicity sockets instead of ethernet cards – Portability device independence: 3COM card or Intel card?

Concurrency and Parallelism Concurrency means multiple threads of computation can make progress, but possibly by sharing the same processor – Like doing homework while chatting on IM Parallelism means leveraging multiple processors to compute a result faster – Like dividing a pile of work among people

Why Concurrency? Consider a web server: while it’s waiting for a response from one client, it could read a request for another client Consider a browser: while it’s waiting for a response from a web server, it wants to react to mouse or keyboard input Concurrency increases/enables responsiveness

Why Parallelism? Because we actually have multiple CPUs! Because matrix multiply goes so much faster! NOTE: Parallelism requires multiple processors, while concurrency also helps on a uniprocessor

Lifecycle of a Thread (or Process) As a thread executes, it changes state: –new: The thread is being created –ready: The thread is waiting to run –running: Instructions are being executed –waiting: Thread waiting for some event to occur –terminated: The thread has finished execution “Active” threads are represented by their TCBs –TCBs organized into queues based on their state

How does OS do it? Kernel: The highly privileged code that carries out lowest level OS functions Use multiple processes, OS schedules them (i.e. multiplexes resources between them) – Each process has its own address space – Each process maintains a list of open files, open network connections … Use multiple threads within a process, either OS or user schedules them – Threads share the process’s address space Threads are cheaper than processes and can more easily share state! But have no isolation.

Strategy 1: force everyone to cooperate – a thread willingly gives up the CPU by calling yield() which calls into the scheduler, which context-switches to another thread – what if a thread never calls yield() ? Strategy 2: use preemption – at timer interrupt, scheduler gains control and context switches as appropriate Recall, an OS needs to mediate access to resources: how do we share the CPU?

Review: Two Thread Yield Example Consider the following code blocks: proc A() { B(); } proc B() { while(TRUE) { yield(); } Suppose we have 2 threads: –Threads S and T Thread S Stack growth A B(while) yield run_new_thread switch Thread T A B(while) yield run_new_thread switch

“THE” System Dijkstra – Algorithm (shortest path) – OS (“THE”) – Software Engineering (“GOTO Considered Harmful”) – Programming Language and Formal Verification

“THE” Multiprogramming System Why Multiprogramming? – A Reduction in turnaround time for short programs – Economic use of peripheral devices – Automatic control of backing store and efficient use of CPU – Need general processor but not all the power

Storage Core ->RAM, Drum ->Disk Separation of Virtual and Physical location Page Swap, the content of the page can be written to a different location on the Drum. No need for consecutive physical locations

Processor A Collection of Sequential Processes Working Together Process State Mutual Synchronization

Hierarchy Level 0 – Present a virtual processor Level 1 – Present virtual segments Level 2 – Present a virtual console Level 3 – Present a buffered IO interface to devices Level 4 – User Programs

Benefit of Layering Limited Interface Fewer Bugs Easier to Test Easier to Communicate

Semaphore Found in Appendix, but so Important! Shared between sequential processes for synchronization P -> decrease ->Possibly lock (if value <0) V -> increase ->unlock P, V are indivisible (atomic)

Backup Slides

os kernel (thread create, destroy, signal, wait, etc.) CPU Kernel-level threads address space thread

Are kernel threads too expensive? Historically yes (thread operations require system calls), but aren’t too bad in practice today, if you use them correctly. Alternatives?

os kernel CPU User-level threads user-level thread library (thread create, destroy, signal, wait, etc.) address space thread

address space thread os kernel CPU User-level threads: what the kernel sees

os kernel (kernel thread create, destroy, signal, wait, etc.) CPU User-level threads: the full story user-level thread library (thread create, destroy, signal, wait, etc.) kernel threads address space thread

No, Google “scheduler activations” for a great discussion of why user-level threads aren’t enough! Are user-level threads the answer?