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

Similar documents
Approaches to Concurrency

Concurrent Programming

CS 261 Fall Mike Lam, Professor. Threads

Concurrent Programming

CMPSCI 230 Computer Systems Principles. Processes

The course that gives CMU its Zip! Concurrency I: Threads April 10, 2001

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Operating System. Chapter 3. Process. Lynn Choi School of Electrical Engineering

Computer Systems Laboratory Sungkyunkwan University

Concurrent Programming

CS510 Operating System Foundations. Jonathan Walpole

Introduction to Threads

Proxy: Concurrency & Caches

EPL372 Lab Exercise 2: Threads and pthreads. Εργαστήριο 2. Πέτρος Παναγή

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 450 Operating System Week 4 Lecture Notes

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

CS 3305 Intro to Threads. Lecture 6

Outline. CS4254 Computer Network Architecture and Programming. Introduction 2/4. Introduction 1/4. Dr. Ayman A. Abdel-Hamid.

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

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Giving credit where credit is due

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Exceptional Control Flow Part I Oct. 17, 2002

THREADS. Jo, Heeseung

Control Flow. Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I. Exceptional Control Flow. Altering the Control Flow

Last class: Today: Thread Background. Thread Systems

Threads. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Exceptional Control Flow Part I

High Performance Computing Course Notes Shared Memory Parallel Programming

CSE 153 Design of Operating Systems Fall 2018

CS 201. Processes. Gerson Robboy Portland State University

Concurrent Programming is Hard! Concurrent Programming. Reminder: Iterative Echo Server. The human mind tends to be sequential

Introduction to PThreads and Basic Synchronization

518 Lecture Notes Week 3

Altering the Control Flow

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Exceptional Control Flow Part I September 22, 2008

Overview. Administrative. * HW 2 Grades. * HW 3 Due. Topics: * What are Threads? * Motivating Example : Async. Read() * POSIX Threads

Lecture #23 Concurrent Programming

Q & A (1) Where were string literals stored? Virtual Address. SSE2033: System Software Experiment 2 Spring 2016 Jin-Soo Kim

Altering the Control Flow

LSN 13 Linux Concurrency Mechanisms

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

Processes: Introduction. CS 241 February 13, 2012

CS333 Intro to Operating Systems. Jonathan Walpole

Processes. Process Concept

CS Lecture 3! Threads! George Mason University! Spring 2010!

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

Threading Language and Support. CS528 Multithreading: Programming with Threads. Programming with Threads

Concurrent Programming

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

Concurrent Programming

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

CS 326: Operating Systems. Process Execution. Lecture 5

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

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

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

Total Score is updated. The score of PA4 will be changed! Please check it. Will be changed

pthreads CS449 Fall 2017

Carnegie Mellon Performance of Mul.threaded Code

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

CS 3723 Operating Systems: Final Review

Review: Easy Piece 1

Process and Its Image An operating system executes a variety of programs: A program that browses the Web A program that serves Web requests

University of Washington What is a process?

CPSC 341 OS & Networks. Threads. Dr. Yingwu Zhu

Warm-up question (CS 261 review) What is the primary difference between processes and threads from a developer s perspective?

Threads. CS3026 Operating Systems Lecture 06

CS307: Operating Systems

Concurrent Server Design Multiple- vs. Single-Thread

Thread and Synchronization

Announcement (1) sys.skku.edu is now available

Chapter 4: Threads. Chapter 4: Threads

Computer Systems Laboratory Sungkyunkwan University

Carnegie Mellon. Processes. Lecture 12, May 19 th Alexandre David. Credits to Randy Bryant & Dave O Hallaron from Carnegie Mellon

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

Chapter 5: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads

Synchronization: Basics

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

CSE 410: Systems Programming

4. Concurrency via Threads

Processes. CS3026 Operating Systems Lecture 05

CSci 4061 Introduction to Operating Systems. (Threads-POSIX)

Processes and Threads. From Processes to Threads. The Case for Threads. The Case for Threads. Process abstraction combines two concepts.

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Lecture 4: Process Management

High Performance Computing Lecture 21. Matthew Jacob Indian Institute of Science

Processes, Exceptional

Concurrent Programming

call connect call read call connect ret connect call fgets Client 2 blocks waiting to complete its connection request until after lunch!

Threads. CS 475, Spring 2018 Concurrent & Distributed Systems

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

Chapter 4: Multithreaded

CMPSC 311- Introduction to Systems Programming Module: Concurrency

Chapter 4: Threads. Operating System Concepts with Java 8 th Edition

POSIX threads CS 241. February 17, Copyright University of Illinois CS 241 Staff

CS370 Operating Systems

Concurrent Programming

Transcription:

Processes & Threads Concurrent Programs Process = Address space + one thread of control Concurrent program = multiple threads of control Multiple single-threaded processes Multi-threaded process 2 1

Concurrent Systems Essential aspects of any concurrent system Execution context - state of a concurrent entity Processes: process context Threads: thread context Scheduling - deciding which context will run next Processes: Operating System scheduler Threads: Library thread scheduler (Pthreads), Java runtime Synchronization - mechanisms that enable execution contexts to coordinate their use of shared resources Semaphores, locks, monitors, condition variables Provided at both operating system and library/language level Distributed Software Systems 3 Processes Def: A process is an instance of a running program. One of the most profound ideas in computer science. Not the same as program or processor Process provides each program with two key abstractions: Logical control flow Each program seems to have exclusive use of the CPU. Private address space Each program seems to have exclusive use of main memory. How are these illusions maintained? Process executions interleaved (multitasking) Address spaces managed by virtual memory system 4 2

Traditional View of a Process Process = process context + code, data, and stack Process context Program context: Stack pointer (SP) Program counter (PC) Kernel context: VM structures Descriptor table brk pointer SP brk PC Code, data, and stack stack shared libraries run-time heap read/write data read-only code/data 0 5 Threads: Motivation Traditional processes created and managed by the OS kernel Process creation expensive - fork system call in UNIX Context switching expensive Cooperating processes - no need for memory protection (separate address spaces) 6 3

Alternate View of a Process Process = thread + code, data, and kernel context Thread (main thread) Code and Data SP stack Thread context: Stack pointer (SP) Program counter (PC) brk PC 0 shared libraries run-time heap read/write data read-only code/data Kernel context: VM structures Descriptor table brk pointer 7 A Process With Multiple Threads Multiple threads can be associated with a process Each thread has its own logical control flow (sequence of PC values) Each thread shares the same code, data, and kernel context Each thread has its own thread id (TID) Thread 1 (main thread) Shared code and data Thread 2 (peer thread) stack 1 Thread 1 context: SP1 PC1 0 shared libraries run-time heap read/write data read-only code/data Kernel context: VM structures Descriptor table brk pointer stack 2 Thread 2 context: SP2 PC2 8 4

Threads Execute in same address space separate execution stack, share access to code and (global) data Smaller creation and context-switch time Can exploit fine-grain concurrency 9 Creating processes UNIX fork system call Used in conjunction with exec system call 10 5

fork: Creating new processes int fork(void) creates a new process (child process) that is identical to the calling process (parent process) returns 0 to the child process returns child s pid to the parent process if (fork() == 0) { printf("hello from child\n"); } else { printf("hello from parent\n"); } Fork is interesting (and often confusing) because it is called once but returns twice Creating and Using threads Pthreads Multi-threading Library API for pthread_create, pthread_join, pthread_self, pthread_exit, pthread_detach Java provides a Runnable interface and a Thread class as part of standard Java libraries users program threads by implementing the Runnable interface or extending the Thread class Distributed Software Systems 12 6

Concurrent Systems Essential aspects of any concurrent system Execution context - state of a concurrent entity Processes: process context Threads: thread context Scheduling - deciding which context will run next Processes: Operating System scheduler Threads: Library thread scheduler (Pthreads), Java runtime Synchronization - mechanisms that enable execution contexts to coordinate their use of shared resources Semaphores, locks, monitors, condition variables Provided at both operating system and library/language level Distributed Software Systems 13 Road Map Next two lectures: Processes & Signals in UNIX Repetition of material discussed in CS 367 Assignment 1 (Shell Lab) Thread creation and management in Java and Pthreads (one lecture) Process & Thread synchronization mechanisms (two three lectures) 14 7