Arvind Krishnamurthy Spring Threads, synchronization, scheduling Virtual memory File systems Networking

Similar documents
Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Lecture 4: Memory Management & The Programming Interface

W4118 Operating Systems. Junfeng Yang

Spring CS 170 Exercise Set 1 (Updated with Part III)

CS162 Operating Systems and Systems Programming Lecture 3. Concurrency: Processes, Threads, and Address Spaces. Review: History of OS

Disciplina Sistemas de Computação

Processes and Threads

Chapter 3: Processes. Operating System Concepts 8th Edition,

Processes. Process Concept

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

CS 450 Operating System Week 4 Lecture Notes

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Page 1. Virtual Machines (Recap)" Nachos: Virtual OS Environment" System Virtual Machines: Layers of OSs"

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

CSE 153 Design of Operating Systems Fall 2018

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

Page 1. Virtual Machines (Recap)" Nachos: Virtual OS Environment (Recap)" System VMs: Layers of OSs (Recap)"

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

CSCE 313: Intro to Computer Systems

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

CHAPTER 2: PROCESS MANAGEMENT

Lecture 4: Threads; weaving control flow

CS5460: Operating Systems

CS Lecture 2! Processes! George Mason University! Fall 2010!

CSE 120 Principles of Operating Systems

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

CSE 120 Principles of Operating Systems

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

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

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Processes and Threads

Slide 6-1. Processes. Operating Systems: A Modern Perspective, Chapter 6. Copyright 2004 Pearson Education, Inc.

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

CSE 120 Principles of Operating Systems

Lecture 2 Process Management

Chapter 3: Processes. Operating System Concepts 8th Edition

Processes. CS3026 Operating Systems Lecture 05

Announcements Processes: Part II. Operating Systems. Autumn CS4023

Chapter 4: Processes. Process Concept

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 5: Threads. Outline

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

Chapter 4: Processes

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

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

Chapter 3: Processes. Operating System Concepts Essentials 8 th Edition

CSC 539: Operating Systems Structure and Design. Spring 2006

What is a Process. Processes. Programs and Processes. System Classification 3/5/2013. Process: An execution stream and its associated state

Processes & Threads. Recap of the Last Class. Layered Structure. Virtual Machines. CS 256/456 Dept. of Computer Science, University of Rochester

THREADS. Jo, Heeseung

CS 326: Operating Systems. Process Execution. Lecture 5

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

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

Announcements/Reminders

Distributed Systems CSCI-B 534/ENGR E-510. Spring 2019 Instructor: Prateek Sharma

Threads. Computer Systems. 5/12/2009 cse threads Perkins, DW Johnson and University of Washington 1

ICS Principles of Operating Systems

Computer Systems II. First Two Major Computer System Evolution Steps

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

Process. Program Vs. process. During execution, the process may be in one of the following states

Processes and Non-Preemptive Scheduling. Otto J. Anshus

CS3733: Operating Systems

Chapter 3: Processes

ELEC 377 Operating Systems. Week 1 Class 2

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

CS307: Operating Systems

Killing Zombies, Working, Sleeping, and Spawning Children

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Chapter 4: Threads. Chapter 4: Threads

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

518 Lecture Notes Week 3

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

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

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

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

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

Computer Systems Laboratory Sungkyunkwan University

Yi Shi Fall 2017 Xi an Jiaotong University

Part Two - Process Management. Chapter 3: Processes

Lecture 5: Concurrency and Threads

Operating System Structure

OS Structure, Processes & Process Management. Don Porter Portions courtesy Emmett Witchel

CS 153 Design of Operating Systems Winter 2016

Multithreading. Reading: Silberschatz chapter 5 Additional Reading: Stallings chapter 4

Chapter 4: Multithreaded Programming

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

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

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Lecture 2 Fundamental OS Concepts. Bo 2018, Spring

Operating Systems CMPSC 473. Process Management January 29, Lecture 4 Instructor: Trent Jaeger

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

What is a Process? Processes and Process Management Details for running a program

What s in a process?

CS510 Operating System Foundations. Jonathan Walpole

Transcription:

Concurrency Arvind Krishnamurthy Spring 2004 Today s lecture Semester roughly divided into: Threads, synchronization, scheduling Virtual memory File systems Networking Next 2.5 weeks: threads and synchronization Today: thread basics Friday: C++ tutorial Wednesday: thread implementation 1

Process Environments Uniprogramming: 1 process at a time Cooperative timesharing : mostly PCs, vintage OSes Easy for OS, hard for user (generally) Does not deal with concurrency (by defining it away) Violates isolation: Infinite loops OS Multiprogramming: > 1 process at a time Time-sharing: CTSS, Multics, Unix, VMS, NT, OS Why concurrency? Operating systems have two general functions: A. Standard services: Provide standard facilities that everyone needs Examples: standard libraries, file systems, windowing systems B. Coordinator: allow several things to work together Examples: memory protection, virtual memory OS has to coordinate all the activity on a machine Requests from multiple users, I/O interrupts Decompose hard problems into simpler ones Instead of dealing with everything at once, deal with one at a time 2

Processes Process: OS abstraction to represent what is needed to run a single program Formally, a process is a sequential stream of execution in its own address space Two parts to a process: Sequential execution: no concurrency inside a process everything happens sequentially Process state: everything that is necessary to run the process Question: What is typically part of the process state? In other words, suppose you want to migrate a process what would you have to transport to the new machine? Program vs. process main() { foo() foo() { Program main() { foo() foo() { Process heap stack main foo registers PC 3

Program vs. process (cont d) Process > program Program is just part of process state Example: many users can run the same program (creating different processes) Process < program A program can invoke more than one process Example: cc starts up cpp, cc1, cc2, as, ld (each are programs themselves) Process creation in Unix Each process has its own state Even if two processes are created from the same executable, they will still have different state associated with them When a process clones itself using fork, a separate copy is created int x = 1; int pid; main() { pid = fork(); x = x + 1; Updates made on different variables 4

Process creation in Unix (contd.) How to make processes: fork clones a process exec overlays the current process if((pid = fork()) == 0) { /* child process */ exec( foo ); /* exec does not return */ else /* parent */ wait(pid); /* wait for child to finish */ Question: Is this a good interface? Announcements Zheng Ma is the TA for the class Email: zheng.ma@yale.edu Please put cs422 in subject line Assignment 0 is on the class website Each person needs to this separately Due: Jan 26 th 5

Processes, Threads, Address Spaces Process: Thread(s) + Address space Thread: sequential execution stream within a process Provides concurrency Address space: state needed to run a program Execution context or Container for execution stream Literally, all the memory addresses that can be touched by the program Provides illusion of program having its own machine Multithreading: single program composed of a number of different concurrent activities Thread creation in Nachos Thread creation in Nachos is very explicit void SimpleThread (int which) { int num; for (num=0; num<5; num++) printf( *** thread %d looped %d times\n, which, num); void ThreadTest() { Thread *t = new Thread( forked thread ); t->fork(simplethread, 1); SimpleThread(0); What is the output? Depends on the implementation 6

Explicit Yields void SimpleThread (int which) { int num; for (num=0; num<5; num++) { printf( *** thread %d looped %d times\n, which, num); currentthread->yield(); void ThreadTest() { Thread *t = new Thread( forked thread ); t->fork(simplethread, 1); SimpleThread(0); Thread State Can be classified into two types: Private Shared Shared state Contents of memory (global variables, heap) File system Private state Program counter Registers Stack 7

Threads Share Memory int done[2] = {0, 0; void SimpleThread (int which) { int num; for (num=0; num<5; num++) printf( *** thread %d looped %d times\n, which, num); done[which] = 1; void ThreadTest() { Thread *t = new Thread( forked thread ); t->fork(simplethread, 1); SimpleThread(0); while (!done[1]); // Perform work that incorporates results from two threads Classifying State int x; void foo() { int y; x = 1; y = 1; global variable stack variable main() { int *p; p = (int *)malloc(sizeof(int)); *p = 1; heap access 8

Address Space Properties Addresses of global variables defined at link-time Addresses of heap variables defined at malloc-time int x; main() { int *p = malloc(sizeof(int)); printf( %x %x, &x, p); // &x will never change across executions, p might Stack Variables Addresses of stack variables defined at call-time void foo() { int x; printf( %x, &x); void bar() { int y; foo(); main() { foo(); bar(); // different addresses will get printed 9

Thread State Shared state: Global variables Heap variables Private state: Stack variables Registers When thread switch occurs, OS needs to save and restore private state Thread State int done[2] = {0, 0; void SimpleThread (int which) { int num; for (num=0; num<5; num++) printf( *** thread %d looped %d times\n, which, num); done[which] = 1; printf( %x %x\n, done, &num); // diff. Addresses for num void ThreadTest() { Thread *t = new Thread( forked thread ); t->fork(simplethread, 1); SimpleThread(0); while (!done[1]); // Perform work that incorporates results from two threads 10

Wrap Up Threads encapsulate concurrency Address spaces encapsulate protection Thread is active, address space is passive Examples: MS/DOS --- one thread, one address space Old Unix --- one thread per address space, many address spaces New Unix (Linux, Solaris), Win NT, Mach --- many threads per address space, many address spaces Embedded systems (VxWorks, JavaOS) --- many threads, one address space (either no need for protection or it is achieved via other means) 11