CS 162 Discussion Section Week 2. Who am I? Prashanth Mohan Office Hours: 11-12pm Tu W at.

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.
Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
Introduction to Operating Systems CS-2301 B-term Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials.
Operating Systems CS451 Brian Bershad
Operating Systems and Systems Programming CS162 Teaching Staff.
Computer Science 162 Discussion Section Week 2. Agenda Recap “What is an OS?” and Why? Process vs. Thread “THE” System.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
OS Spring’03 Introduction Operating Systems Spring 2003.
Threads CSCI 444/544 Operating Systems Fall 2008.
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.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
ThreadsThreads operating systems. ThreadsThreads A Thread, or thread of execution, is the sequence of instructions being executed. A process may have.
CS 162 Discussion Section Week 1 (9/9 – 9/13) 1. Who am I? Kevin Klues Office Hours:
Implementing Processes and Process Management Brian Bershad.
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.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Background: Operating Systems Brad Karp UCL Computer Science CS GZ03 / M th November, 2008.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Operating Systems and Systems Programming CS162 Teaching Staff.
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
CS 162 Discussion Section Week 2. Who am I? Wesley Chow Office Hours: 12pm-2pm 411 Soda Does Monday 1-3 work for everyone?
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
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.
12/2/091 What is an Operating System Andy Konwinski CS61CL Dec 2, 2009 Lecture 13 UCB CS61CL F09 Lec 13.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Threads. Readings r Silberschatz et al : Chapter 4.
Goals for Today How do we provide multiprogramming? What are Processes? How are they related to Threads and Address Spaces? Note: Some slides and/or pictures.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-2: Threads Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
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.
Threads by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Introduction to Operating Systems Concepts
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Introduction to threads
Processes and threads.
Operating Systems CMPSC 473
CSCI 511 Operating Systems Chapter 3,4 (Part A) Processes and Threads
CS 6560: Operating Systems Design
Jonathan Walpole Computer Science Portland State University
Operating System (013022) Dr. H. Iwidat
Chapter 4: Multithreaded Programming
Chapter 4 Threads.
Chapter 4: Threads.
COP 4600 Operating Systems Fall 2010
Operating Systems and Systems Programming
CSCI 511 Operating Systems Chapter 3,4 (Part A) Processes and Threads
Threads, SMP, and Microkernels
Chapter 15, Exploring the Digital Domain
More examples How many processes does this piece of code create?
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads and Concurrency
CSE 451: Operating Systems Winter 2003 Lecture 1 Course Introduction
Processes and Process Management
Operating Systems Lecture 3.
Operating Systems (CS 340 D)
Chapter 4: Threads.
Operating Systems: A Modern Perspective, Chapter 6
CS510 Operating System Foundations
CSE 153 Design of Operating Systems Winter 2019
CSE 451: Operating Systems Autumn 2003 Lecture 1 Course Introduction
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
CS703 – Advanced Operating Systems
Presentation transcript:

CS 162 Discussion Section Week 2

Who am I? Prashanth Mohan Office Hours: 11-12pm Tu W at 411 Soda Hall Research: Data Security Tech for Sustainability

Administrivia Register with Piazza About the groups Meetings with TA for reviews. Get to know Nachos

What is an OS and What does it do?

Why do you 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: tiCOM card or Intel card?

Why is concurrency hard? What do you need to get concurrency working?

Concurrency Concurrency means multiple threads of computation can make progress, but possibly by sharing the same processor – Like doing homework while chatting on IM 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

Different levels of abstraction Threads Processes Symmetric multithreading Distributed systems (Single system image)

What is a thread? A thread of execution is the smallest unit of processing that can be scheduled by an operating system. – Wikipedia circa Jan ‘12 What resources does a thread have?

Single and Multi Threading

Threading Issues Semantics of fork() and exec() system calls Thread cancellation Signal handling Thread pools Thread specific data Scheduler activations

How do you have multiple threads? Code Global Data Heap Stack 1 Stack 2 Address Space

What is the difference between a Thread and a Process?

What is a Process? Process Control Block

Process Address Space Program Address Space What is an address space? What does this mean in terms of hardware?

Operating System Memory Management Prog 1 Virtual Address Space 1 Prog 2 Virtual Address Space 2 Code Data Heap Stack Code Data Heap Stack Data 2 Stack 1 Heap 1 OS heap & Stacks Code 1 Stack 2 Data 1 Heap 2 Code 2 OS code OS data Translation Map 1Translation Map 2 Physical Address Space

When and how do you switch between processes?

Scheduling states

Context Switching

An OS needs to mediate access to resources: how do we share the CPU? 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 pre-emption – 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?

From Lecture: Two Thread Yield 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

Concurrent Programs Two threads, A and B, compete with each other –One tries to increment a shared counter –The other tries to decrement the counter Thread AThread B i = 0;i = 0; while (i -10) i = i + 1; i = i – 1; printf(“A wins!”);printf(“B wins!”); Assume that memory loads and stores are atomic, but incrementing and decrementing are not atomic Who wins? Could be either Is it guaranteed that someone wins? Why or why not? What it both threads have their own CPU running at same speed? Is it guaranteed that it goes on forever?

Parallelism Parallelism means leveraging multiple processors to compute a result faster – Like dividing a pile of work among people Why Parallelism? – Because we actually have multiple CPUs! – Because matrix multiply goes so much faster!

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.

Fetch Exec R0 … R31 F0 … F30 PC … Data1 Data0 Inst237 Inst236 … Inst5 Inst4 Inst3 Inst2 Inst1 Inst0 Addr 0 Addr Recall (61C): What happens during execution? Execution sequence: –Fetch Instruction at PC –Decode –Execute (possibly using registers) –Write results to registers/mem –PC = Next Instruction(PC) –Repeat PC