Concurrency Terminology

Similar documents
Lesson 1. Concurrency. Terminology Concurrency in Systems Problem Examples Copyright Teemu Kerola 2009

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

CS377P Programming for Performance Multicore Performance Multithreading

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Contribution:javaMultithreading Multithreading Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team

Process Management And Synchronization

Concurrent Computing

Dealing with Issues for Interprocess Communication

Concurrency and Synchronisation

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Concurrency: Deadlock and Starvation. Chapter 6

Learning Outcomes. Concurrency and Synchronisation. Textbook. Concurrency Example. Inter- Thread and Process Communication. Sections & 2.

Concurrency and Synchronisation

Chapter 6: Process Synchronization

PROCESS SYNCHRONIZATION

Programming Languages

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

System Software. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 13

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

CSC 4320 Test 1 Spring 2017

Introduction to Concurrent Software Systems. CSCI 5828: Foundations of Software Engineering Lecture 08 09/17/2015

Threading and Synchronization. Fahd Albinali

Last Class: Monitors. Real-world Examples

Interprocess Communication By: Kaushik Vaghani

Synchronization I. Jo, Heeseung

SPIN, PETERSON AND BAKERY LOCKS

Introduction to Concurrent Software Systems. CSCI 5828: Foundations of Software Engineering Lecture 12 09/29/2016

ENGR 3950U / CSCI 3020U UOIT, Fall 2012 Quiz on Process Synchronization SOLUTIONS

Synchronization. Peter J. Denning CS471/CS571. Copyright 2001, by Peter Denning

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - XI Deadlocks - II. Louisiana State University

Concurrency. Chapter 5

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10)

Roadmap. Bounded-Buffer Problem. Classical Problems of Synchronization. Bounded Buffer 1 Semaphore Soln. Bounded Buffer 1 Semaphore Soln. Tevfik Ko!

Roadmap. Readers-Writers Problem. Readers-Writers Problem. Readers-Writers Problem (Cont.) Dining Philosophers Problem.

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10

Concept of a process

THREADS & CONCURRENCY

Classical Synchronization Problems. Copyright : University of Illinois CS 241 Staff 1

Sistemas Operacionais I. Valeria Menezes Bastos

Semaphores (by Dijkstra)

CSE 4/521 Introduction to Operating Systems

CS 31: Intro to Systems Threading & Parallel Applications. Kevin Webb Swarthmore College November 27, 2018

Chapter 6: Process [& Thread] Synchronization. CSCI [4 6] 730 Operating Systems. Why does cooperation require synchronization?

Ver teil tes Rechnen und Parallelprogrammierung: Introduction to Multi-Threading in Java

Lecture 3: Intro to Concurrent Processing using Semaphores

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Algorithmic Verification. Algorithmic Verification. Model checking. Algorithmic verification. The software crisis (and hardware as well)

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

Process Synchronization

Multicore and Multiprocessor Systems: Part I

Explain briefly how starvation may occur in process scheduling. (2 marks)

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Interprocess Communication and Synchronization

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

Process Synchronization(2)

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

CS450/550 Operating Systems

What are they? How do we represent them? Scheduling Something smaller than a process? Threads Synchronizing and Communicating Classic IPC problems

Process Synchronization

CSE Traditional Operating Systems deal with typical system software designed to be:

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

Process Synchronization

Midterm Exam. October 20th, Thursday NSC

Concurrency and Synchronisation. Leonid Ryzhyk

Chapter 2 Processes and Threads

Process Synchronization(2)

Chendu College of Engineering & Technology

Concurrency: State Models & Design Patterns

OS Process Synchronization!

Lesson 6: Process Synchronization

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Synchronization Principles

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

Synchronization Principles II

Concurrency, Thread. Dongkun Shin, SKKU

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

Semaphores INF4140. Lecture 3. 0 Book: Andrews - ch.04 ( ) INF4140 ( ) Semaphores Lecture 3 1 / 34

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Semaphores. To avoid busy waiting: when a process has to wait, it will be put in a blocked queue of processes waiting for the same event

Semaphores. Semaphores. Semaphore s operations. Semaphores: observations

Introduction to Operating Systems

Operating Systems. Synchronization Based on Ch. 5 of OS Concepts by SGG

CS450/550 Operating Systems

Operating Systems. Thread Synchronization Primitives. Thomas Ropars.

Synchronization in Concurrent Programming. Amit Gupta

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack

CS Operating Systems

CS Operating Systems

Chapter 6 Synchronization

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018

PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug

Chapter 6: Process Synchronization. Operating System Concepts 9 th Edit9on

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

Transcription:

Lesson 1 Concurrency Ch 1 [BenA 06] Terminology Concurrency in Systems Problem Examples Solution Considerations 1 Concurrency Terminology Process, thread tavallinen ohjelma Ordinary program Sequential process, one thread of execution Concurrent program rinnakkaisohjelma Many sequential process, that may be executed in parallel multi-threaded Java-program, runs in one system Web-application, distributed on many systems Multiprocessor system, parallel program Many sequential or concurrent processes are executed in parallel Many architectures, no winner yet Distributed system, distributed program No shared memory Interconnected systems prosessi, säie rinnakkaisohjelma, moniprosessorisovellus hajautettu ohjelma 2 Lecture 1: Concurrency 1

Concurrency at HW-level Processor Execute many instructions in parallel Execute many threads in parallel l Execute many processes in parallel System Many processors/display processors Many I/O devices LAN or WAN Many systems (in clusters) Internet and other networks Many sub-systems STI Cell http://ops.fhwa.dot.gov/publications/telecomm_handbook/images/fig2-14.gif 3 Problem Moore s Law will not give us (any more) faster processors But it gives us now more processors on one chip Multicore CPU Chip-level multiprocessor (CMP) Herb Sutter, A Fundamental Turn Toward Concurrency in SW, Dr. Dobb s Journal, 2005. http://www.ddj.com/web-development/184405990;jsessionid=bw05dmmaot3zgqsndlpckh0cjunn2jvn?_requestid=1416784 4 Lecture 1: Concurrency 2

(hyper- threads) Borkar, Dubey, Kahn, et al. Platform 2015. Intel White Paper, 2005. http://download.intel.com/technology/computing/archinnov/platform2015/download/platform_2015.pdf 5 The Multicore Challenge We have a heat-barrier dead-end to develop simple to program single core chips So, we leap to multicore chips in pursuit for ever higher processing power Parallel Challenge: how to use these multicore computers efficiently to speed up computing? Concurrent programming We should have launched a parallel programming Manhattan h Project a long time ago Would need now 100 s of millions ($), not 10 s of millions ($) per year for long term funding David Patterson, The Multicore Challenge, The CCC Blog, Aug 26, 2008, http://www.cccblog.org/2008/08/26/the-multicore-challenge/ 6 Lecture 1: Concurrency 3

Concurrency at HW-level Machine language code Many instructions at execution concurrently Comp.Org. I, II (tito, tikra) Logically one at a time (von Neumann arch.) At least one instruction cluster at a time Program execution may stop/pause after any instruction High level programming language code Process switch can occur at any time No handle on process switch times (in general) Operating system & external events decide Need to synchronize with other programs Need to communicate with other programs Need to get handle to process switch occurrences Other processes may be in execution at the same time 7 Problem Free Concurrency? No problems at all? Concurrent threads in execution No shared data, no I/O (or private I/O) No communication, no synchonization No shared data, but data in shared memory Bus congestion may be problem Concurrency problem (bus use) solved in HW Slows down execution Communication/synchronization is needed eventually Combine results from concurrent threads 8 Lecture 1: Concurrency 4

Concurrency Problems Keep data consistent Update all fields of shared data Complete writing a buffer before reading starts Synchronize with someone Complete writing before reading starts Give money only after bank card is taken Compile new Java class before execution resumes Do not wait forever, if the other party is dead Communicate with someone Send a short message to someone Send data to be processed to someone Send 2 GB data for remote processing, wait for result 9 Playstation 3 Concurrency Examples Use effectively 2 cells, 9 processors at each cell Use two different processor architectures Divide-and-conquer or filtering approach? Desktop PC Use effectively 4 processors and a graphics adapter to generate graphics for fast moving game Divide processing for CPU s and graphics adapter? Utilize all 4 processors Control shared access to game data base In memory? In disk? In a file server in Japan? 10 Lecture 1: Concurrency 5

Concurrency Examples Multithreaded Java program on a multiprocessor system Access to shared data structures http://www.cs.helsinki.fi/u/kerola/rio/java/examples/plusminus1.java vera: javac Plusminus1.java vera: time java Plusminus1 click http://www.cs.helsinki.fi/u/kerola/rio/java/examples/plusminus8.java vera: javac Plusminus8.java click vera: time java Plusminus8 >& a & vera: ps -eo pcpu,pid,user,args sort -k 1 -r head -10 vera has 8 processors visible to operating system Why is result different with extra output? Synchronization between threads Displaying these slides from file server Transfer slides to local buffer and display them 11 Concurrency Examples Linux Beowulf 6 node cluster How to solve weather forecast Hirlam model as fast as possible? How to best distribute data? Solution scalable to 100 or 1000 nodes? Web server How to serve 1000 or 10000 concurrent requests with 100 file servers Most reads, but some writes to same files? How to guarantee consistent reads with simultaneous writes? 12 Lecture 1: Concurrency 6

Concurrency Examples Operating system How to keep track of all concurrent processes, each with ihmultiple li l threads? d? What type of concurrency control utilities should be offered to user programs? Which utilities offered to OS services? How do we guarantee that the system does not freeze How to write an 8-disk disk controller device driver? How do I guarantee, that nothing disturbs an ongoing process switch? 13 Concurrency Problem Solution Level Processor level, i.e., below machine language level HW solutions, automatic, no errors Need to understand, this is where it really happens Machine language level Specific (HW) machine instructions for concurrency solutions Clever solutions without specific instructions Need to be used properly, this is where it really happens Program level, i.e., programming language level SW solutions, many possibilities for error Solve problem by programming the solution your self Very error prone Requires privileged execution mode (usually) Solve problem directly by invoking certain available library services Error prone may invoke wrong routines at wrong times Solve problem by letting available library service do it all for you Not suitable always may not fit to your problem well 14 Lecture 1: Concurrency 7

Library Solutions for Concurrency Problems Programming language run-time library E.g., Java thread management Usually within one process (in one system) Any program can use May be implemented directly or with OS-libraries Operating systems services (libraries) Any process can use these, not so portable across OS s Usually only choice between many processes Exception: programming language library that implements its services with OS Only choice between many systems May need privileged execution mode Some services reserved only for OS programs or utilities 15 Basic Concurrency Problem Types Mutual exclusion, poissulkemisongelma Mutex One or more critical code segments, i.e., critical section At most one process executing critical section (of code) at any time I.e., at most one process holds this resource (code) at any time Synchronization i Communication P data Q P 1 P 3 P 4 P Person.id = idx; Person.name name = namex; Person.age = agex; P 2 continue Q Q 16 Lecture 1: Concurrency 8

Basic Concurrency Problems Dining philosophers think-eat cycle need 2 forks to eat can take one fork at a time no discussion question: what protocol to use to reserve forks? multi-process synchronization Avoid deadlock Avoid starvation Prove correctness Edsger Dijkstra, 1971 Aterioivat filosofit http://en.wikipedia.org photo 2002 Hamilton Richards, http://www.cs.utexas.edu/users/ewd/ewdwww.jpg 17 Dijkstra Basic Concurrency Problems Fred G. Martin http://www.cs.uml.edu/~fredm/courses/91.308-fall05/assignment7.shtml Sleeping barber Nukkuva parturi One barber, one barber chair Waiting room with n chairs No customers? Barber sleeps until arriving customer wakes him up Customer arrives? Barber sleeps? Wake him up! Barber busy and empty chairs? Reserve one and wait. o/w leave Question: what protocol for barber & customers? Inter-process communication, synchronization? Avoid deadlock and starvation 18 Lecture 1: Concurrency 9

Basic Concurrency Problems Bakery algorithm Baker, ticket machine Each arriving customer gets a ticket number Customers are served in increasing ticket number order Question: how to implement the ticket machine In distributed system? With/without shared memory? Multi-threaded mutual exclusion Critical section use order? Leipurin vuorolappu http://research.microsoft.com/users/ lamport/leslie.gif Leslie Lamport, 1974 19 Basic Concurrency Problems Producer-Consumer Bounded shared buffer area Producers insert data items Consumers take data items in arriving order Full buffer? Producer blocks Empty buffer? Consumer blocks tuottaja-kuluttaja P 2 P 1 data C 1 data data C 2 P 3 Question: protocol for producer/consumer Communication, synchronization Unix/linux pipe Avoid deadlock, starvation 20 Lecture 1: Concurrency 10

Basic Concurrency Problems Readers-writers Shared data-base Many can read same item concurrently Only one can write at a time Reading not allowed at that time Readers have priority over writers Question: protocol for readers/writers? Mutual exclusion, synchronization Avoid deadlock, starvation lukijat-kirjoittajat read read write 21 System Considerations Different threads in same process? Who controls o thread switching? Application or OS? Different processes in same system? Shared memory or not? Many threads in each process? Different threads/processes in processors grid? No shared memory Different threads/processes in distributed system? No shared memory Large communication delays 22 Lecture 1: Concurrency 11

Solution Considerations Solution at application level without HW support Do everything from scratch Solution at application level with HW support Use special machine language level instructions or structures Solution at operating system level Use utilities in operating system library Solution at programming language level Use utilities in programming language age library Solution at network level Use utilities in some network server Need to understand what really happens 23 Terminology Summary Concurrency in systems Concurrency problem examples Educational: philophers, barber, bakery Practical: consumer-producer, readers-writers Solution considerations 24 Lecture 1: Concurrency 12