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

Similar documents
Concurrency Terminology

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

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

Process Management And Synchronization

Dealing with Issues for Interprocess Communication

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Concurrency and Synchronisation

Concurrent Computing

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

Threading and Synchronization. Fahd Albinali

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

Synchronization I. Jo, Heeseung

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

SPIN, PETERSON AND BAKERY LOCKS

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

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

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

Concurrency. Chapter 5

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

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

Concept of a process

Interprocess Communication By: Kaushik Vaghani

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

Semaphores (by Dijkstra)

CSC 4320 Test 1 Spring 2017

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

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

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

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

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

Multicore and Multiprocessor Systems: Part I

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Interprocess Communication and Synchronization

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

Last Class: Monitors. Real-world Examples

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

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10

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

Process Synchronization(2)

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

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

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

Process Synchronization

THREADS & CONCURRENCY

Concurrency and Synchronisation. Leonid Ryzhyk

Chapter 2 Processes and Threads

Sistemas Operacionais I. Valeria Menezes Bastos

Process Synchronization(2)

Chendu College of Engineering & Technology

OS Process Synchronization!

Lesson 6: Process Synchronization

CSE 4/521 Introduction to Operating Systems

Synchronization Principles

Lecture 3: Intro to Concurrent Processing using Semaphores

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

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

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

Process Synchronization

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.

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

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

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

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

Lecture 3: Intro to parallel machines and models

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

Chapters 5 and 6 Concurrency

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

Moore s Law. Computer architect goal Software developer assumption

Process Coordination

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

MARUTHI SCHOOL OF BANKING (MSB)

Process Synchronization

Multithreaded Programming Part II. CSE 219 Stony Brook University, Department of Computer Science

MultiThreading. Object Orientated Programming in Java. Benjamin Kenwright

Introducing Shared-Memory Concurrency

CS450/550 Operating Systems


Synchronization Principles II

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

Transcription:

Lesson 1 Concurrency Ch1[B [BenA A06] Terminology Concurrency in Systems Problem Examples Solution Considerations 1

Concurrency Terminology Process, thread Ordinary program tavallinen ohjelma 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 prosessi, Wb Web-application, distributed ib t d on many systems säie Multiprocessor system, parallel program Many sequential or concurrent processes are executed in parallel rinnakkaisohjelma, moniprosessorisovellus Many architectures, no winner yet Ditib Distributed tdsystem, distributed ditib tdprogram No shared memory Interconnected systems hajautettu ohjelma 2

Concurrency at HW-level Processor Execute many instructions in parallel Execute many threads in parallel 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

(hyperthreads) 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 gpower Parallel Challenge: how to use these multicore computers efficiently to speed up computing? Concurrent programming We should have launched a parallel programming Manhattan Project a long time ago Would need now 100 s of millions ($), not 10 sof 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

Concurrency at HW-level Machine language code Comp.Org. I, II Many instructions at execution (tito, tikra) concurrently 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

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 id 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

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

Concurrency Examples Operating system How to keep track of all concurrent processes, each with multiple threads? 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

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 i 15

Basic Concurrency Problem Types Mutex Mutual exclusion, poissulkemisongelma 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 P (code) at any time P 2 1 Synchronization Communication P data Q P 3 P 4 P Person.id = idx; Person.name = namex; Person.age = agex; continue Q Q 16

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 Sleeping barber b Nukkuva parturi One barber, one barber chair Waiting room with n chairs No customers? Barber sleeps until arriving customer wakes him up Customer arrives? http://www.cs.uml.edu/~fredm/courses/91.308-fall05/assignment7.shtml 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

Basic Concurrency Problems Bakery algorithm Leipurin vuorolappu 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 ib t dsystem? With/without shared memory? Multi-threaded mutual exclusion Critical section use order? 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 tuottaja-kuluttaja Full buffer? P 2 Producer blocks Empty buffer? Consumer blocks P 1 P 3 data data data Question: protocol for producer/consumer Communication, synchronization Unix/linux pipe Avoid deadlock, starvation C 1 C 2 20

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 re ead re ead write 21

System Considerations Different threads in same process? Who controls 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

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 library Solution at network level Use utilities in some network server Need to understand what really happens 23

Summary Terminology Concurrency in systems Concurrency problem examples Educational: philophers, h barber, b bakery Practical: consumer-producer, readers-writers Solution considerations 24