G52CON: Concepts of Concurrency

Similar documents
G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency

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

Frequently asked questions from the previous class survey

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Concurrent Programming. Introduction

Concurrency in Object Oriented Programs 1. Object-Oriented Software Development COMP4001 CSE UNSW Sydney Lecturer: John Potter

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

G52CON: Concepts of Concurrency

Module 5: Concurrent and Parallel Programming

CMSC 433 Programming Language Technologies and Paradigms. Concurrency

Concurrency. Lecture 14: Concurrency & exceptions. Why concurrent subprograms? Processes and threads. Design Issues for Concurrency.

Concurrent systems Lecture 1: Introduction to concurrency, threads, and mutual exclusion

Discussion CSE 224. Week 4

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

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

POSIX Threads: a first step toward parallel programming. George Bosilca

POSIX / System Programming

연세대학교전기전자공학과프로세서연구실박사과정김재억.

Concurrent systems Lecture 1: Introduction to concurrency, threads, and mutual exclusion

G52CON: Concepts of Concurrency

Concurrent & Distributed Systems Supervision Exercises

Dealing with Issues for Interprocess Communication

Concurrent Processes Rab Nawaz Jadoon

IV. Process Synchronisation

CHAPTER 2: PROCESS MANAGEMENT

Specific Proposals for the Use of Petri Nets in a Concurrent Programming Course

Last Class: Monitors. Real-world Examples

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

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (II)

Mutual Exclusion and Synchronization

NETW3005 Operating Systems Lecture 1: Introduction and history of O/Ss

IT 540 Operating Systems ECE519 Advanced Operating Systems

SFDV3006 Concurrent Programming

Part I: Communication and Networking

7: Interprocess Communication

Chapter 4: Processes. Process Concept

High Performance Computing Course Notes Shared Memory Parallel Programming

Comp 204: Computer Systems and Their Implementation. Lecture 9: Deadlock

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

Chapter 4: Processes

Chapter 1: Distributed Systems: What is a distributed system? Fall 2013

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

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

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

Introduction to programming with semaphores Fri 1 Sep 2017

Chapter 5: Synchronization 1

Frequently asked questions from the previous class survey

Concurrency: a crash course

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

VALLIAMMAI ENGINEERING COLLEGE

Learning Outcomes. Processes and Threads. Major Requirements of an Operating System. Processes and Threads

Operating Systems. Lecture 09: Input/Output Management. Elvis C. Foster

Formal Specification and Verification

5. Synchronization. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

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

Real-Time and Concurrent Programming Lecture 4 (F4): Monitors: synchronized, wait and notify

Operating Systems. Thread Synchronization Primitives. Thomas Ropars.

Process Management And Synchronization

MultiJav: A Distributed Shared Memory System Based on Multiple Java Virtual Machines. MultiJav: Introduction

Processes and Threads. Processes: Review

CSE 153 Design of Operating Systems Fall 2018

Processes and Threads

Chapters 5 and 6 Concurrency

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 2 Solution

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules

Operating Systems Overview. Chapter 2

REAL-TIME MULTITASKING KERNEL FOR IBM-BASED MICROCOMPUTERS

1. Introduction to Concurrent Programming

Applications of Formal Verification

Chapter 6: Process Synchronization

Performance Throughput Utilization of system resources

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

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

COSC243 Part 2: Operating Systems

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

CSC 280 Operating System Principles

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

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

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

Boca Raton Community High School AP Computer Science A - Syllabus 2009/10

Timers 1 / 46. Jiffies. Potent and Evil Magic

Shared Objects & Mutual Exclusion

CONCURRENT/DISTRIBUTED PROGRAMMING ILLUSTRATED USING THE DINING PHILOSOPHERS PROBLEM *

Concurrency: Deadlock and Starvation. Chapter 6

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

CSI3131 Final Exam Review

Synchronization I. Jo, Heeseung

G52CON: Concepts of Concurrency Lecture 15: Message Passing. Gabriela Ochoa School of Computer Science & IT

Chapter 5 Asynchronous Concurrent Execution

CS420: Operating Systems

Operating System Design

10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4

SISTEMI CONCORRENTI E DI RETE LS II Facoltà di Ingegneria - Università di Bologna - Cesena - a.a / 2009 COURSE PRESENTATION

Execution Architecture

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

Transcription:

G52CON: Concepts of Concurrency Lecture 1: Introduction Brian Logan School of Computer Science bsl@cs.nott.ac.uk

Outline of this lecture" why concurrency... applications of concurrency sequential vs concurrent programs module aims & objectives scope of the module & outline syllabus assessment suggested reading Brian Logan 2014 G52CON Lecture 1: Introduction 2

Example: ParticleApplet" ParticleApplet creates n Particle objects, sets each particle in autonomous continuous motion, and periodically updates the display to show their current positions: the applet runs in its own Java thread; each particle runs in its own Java thread which computes the position of the particle; an additional thread periodically checks the positions of the particles and draws them on the screen; in this example there are at least 12 threads and possibly more, depending on how the browser handles applets. Brian Logan 2014 G52CON Lecture 1: Introduction 3

Why concurrency..." It is often useful to be able to do several things at once: when latency (responsiveness) is an issue, e.g., server design, cancel buttons on dialogs, etc.; when you want to parallelise your program, e.g., when you want to distribute your code across multiple processors; when your program consists of a number of distributed parts, e.g., client server designs. Brian Logan 2014 G52CON Lecture 1: Introduction 4

but I only have a single processor" Concurrent designs can still be effective even if you only have a single processor/core: many sequential programs spend considerable time blocked, e.g. waiting for memory or I/O this time can be used by another thread in your program (rather than being given by the OS to someone else s program) even if your code is CPU bound, it can still be more convenient to let the scheduler (e.g. JVM) work out how to interleave the different parts of your program than to do it yourself it s also more portable, if you do get another processor/more cores Brian Logan 2014 G52CON Lecture 1: Introduction 5

Example: file downloading" Consider a client server system for file downloads (e.g. BitTorrent, FTP) without concurrency it is impossible to interact with the client (e.g., to cancel the download or start another one) while the download is in progress the server can only handle one download at a time anyone else who requests a file has to wait until your download is finished with concurrency the user can interact with the client while a download is in progress (e.g., to cancel it, or start another download) the server can handle multiple clients at the same time Brian Logan 2014 G52CON Lecture 1: Introduction 6

More examples of concurrency" GUI-based applications: e.g., javax.swing Mobile code: e.g., java.applet Web services: HTTP daemons, servlet engines, application servers Component-based software: Java beans often use threads internally I/O processing: concurrent programs can use time which would otherwise be wasted waiting for slow I/O Real Time systems: operating systems, transaction processing systems, industrial process control, embedded systems etc. Parallel processing: simulation of physical and biological systems, graphics, economic forecasting etc. Brian Logan 2014 G52CON Lecture 1: Introduction 7

Sequential programs" All programs are sequential in that they execute a sequence of instructions in a pre-defined order: x = x + 1 LOAD x ADD 1 STORE x There is a single thread of execution or control. Brian Logan 2014 G52CON Lecture 1: Introduction 8

Concurrent programs" A concurrent program is one consisting of two or more processes threads of execution or control x = x + 1 LOAD x ADD 1 STORE x LOAD x STORE y y = x Process A! Process B! Each process is itself a sequential program. Brian Logan 2014 G52CON Lecture 1: Introduction 9

Aspects of concurrency" We can distinguish between: whether the concurrency is required (by the specification) or optional (a design choice made by the programmer); the granularity of the concurrent program, application or system; and how the concurrency is implemented. Brian Logan 2014 G52CON Lecture 1: Introduction 10

Concurrency in specification vs implementation" Concurrency is useful both when we want a program to do several things at once, and as an implementation strategy: in real-time systems concurrency is often implicit in the specification of the problem, e.g., cases where we can t allow a single thread of control to block on I/O; in parallel programming, e.g., weather forecasting, SETI@home, etc., there may be no concurrency in the problem requirements however a concurrent implementation may run faster or allow a more natural problem decomposition. Brian Logan 2014 G52CON Lecture 1: Introduction 11

Granularity of concurrency" The processes in a concurrent program (or more generally, concurrent application or concurrent system) can be at different levels of granularity: threads within a single program, e.g., Java threads within a Java program running on a JVM (lightweight processes); programs running on a single processor or computer (heavyweight or OS processes) this is not usually a concern for applications programmers; programs running on different computers connected by a network. Brian Logan 2014 G52CON Lecture 1: Introduction 12

Implementations of concurrency" We can distinguish two main types of implementations of concurrency: shared memory: the execution of concurrent processes by running them on one or more processors all of which access a shared memory processes communicate by reading and writing shared memory locations; and distributed processing: the execution of concurrent processes by running them on separate processors processes communicate by message passing. Brian Logan 2014 G52CON Lecture 1: Introduction 13

Java Implementations of Concurrency" Java supports both shared memory and distributed processing implementations of concurrency: shared memory: multiple user threads in a single Java Virtual Machine threads communicate by reading and writing shared memory locations; and distributed processing: via the java.net and java.rmi packages threads in different JVMs communicate by message passing or remote procedure call G52CON covers both approaches Brian Logan 2014 G52CON Lecture 1: Introduction 14

Shared memory implementations" We can further distinguish between: multiprogramming: the execution of concurrent processes by timesharing them on a single processor (concurrency is simulated); multiprocessing: the execution of concurrent processes by running them on separate processors which all access a shared memory (true parallelism as in distributed processing). it is often convenient to ignore this distinction when considering shared memory implementations. Brian Logan 2014 G52CON Lecture 1: Introduction 15

Cooperating concurrent processes" The concurrent processes which constitute a concurrent program must cooperate with each other: for example, downloading a file in a web browser generally creates a new process to handle the download while the file is downloading you can also continue to scroll the current page, or start another download, as this is managed by a different process if the two processes don t cooperate effectively, e.g., when updating the display, the user may see only the progress bar updates or only the updates to the main page. Brian Logan 2014 G52CON Lecture 1: Introduction 16

Synchronising concurrent processes" To cooperate, the processes in a concurrent program must communicate with each other: communication can be programmed using shared variables or message passing; when shared variables are used, one process writes into a shared variable that is read by another; when message passing is used, one process sends a message that is received by another; the main problem in concurrent programming is synchronising this communication Brian Logan 2014 G52CON Lecture 1: Introduction 17

Competing processes" Similar problems occur with functionally independent processes which don t cooperate, for example, separate programs on a time-shared computer: such programs implicitly compete for resources; they still need to synchronise their actions, e.g., two programs can t use the same printer at the same time or write to the same file at the same time. In this case, synchronisation is handled by the OS, using similar techniques to those found in concurrent programs. Brian Logan 2014 G52CON Lecture 1: Introduction 18

Structure of concurrent programs" Concurrent programs are intrinsically more complex than single-threaded programs: when more than one activity can occur at a time, program execution is necessarily nondeterministic; code may execute in surprising orders any order that is not explicitly ruled out is allowed a field set to one value in one line of code in a process may have a different value before the next line of code is executed in that process; writing concurrent programs requires new programming techniques Brian Logan 2014 G52CON Lecture 1: Introduction 19

Example: the Ornamental Gardens problem" A large ornamental garden is open to members of the public who can enter through either of two turnstiles West" turnstile" Garden East" turnstile" Counter" the owner of the garden hires a student to write a concurrent program to count how many people are in the garden at any one time the program has two processes, each of which monitors a turnstile and increments a shared counter whenever someone enters via that processes turnstile Brian Logan 2014 G52CON Lecture 1: Introduction 20

Why we need a module on concurrent programming" Advantages of concurrency concurrent programs are often more flexible or responsive than singlethreaded programs a concurrent design is more natural for many applications a concurrent design may make better use of system resources Potential problems of concurrency concurrent programs are often more complex than single-threaded programs a concurrent design may entail a performance overhead (though this is often over-stated) concurrency introduces new kinds of bugs testing is much less useful in identifying defects Brian Logan 2014 G52CON Lecture 1: Introduction 21

Module aims" This course introduces the basic principles of concurrent programming and their use in designing programs Aims to convey a basic understanding of the concepts, problems, and techniques of concurrent programming to show how these can be used to write simple concurrent programs in Java to develop new problem solving skills Brian Logan 2014 G52CON Lecture 1: Introduction 22

Module objectives" judge for what applications and in what circumstances concurrent programs are appropriate; design concurrent algorithms using a variety of low-level primitive concurrency mechanisms; analyse the behaviour of simple concurrent algorithms with respect to safety, deadlock, starvation and liveness; apply well-known techniques for implementing common producerconsumer and readers-and-writers applications, and other common concurrency problems; and design concurrent algorithms using Java primitives and library functions for threads, semaphores, mutual exclusion and condition variables. Brian Logan 2014 G52CON Lecture 1: Introduction 23

Scope of the module" will will focus on concurrency from the point of view of the application programmer; we will focus on problems where concurrency is implicit in the problem requirements; we will only consider imperative concurrent programs; we will focus on programs in which process execution is asynchronous, i.e., each process executes at its own rate; and we won t concern ourselves with whether concurrent programs are executed in parallel on multiple processors or whether concurrency is simulated by multiprogramming. Brian Logan 2014 G52CON Lecture 1: Introduction 24

Outline syllabus" The course focuses on four main themes: introduction to concurrency; design of simple concurrent algorithms in Java; correctness of concurrent algorithms; and design patterns for common concurrency problems. Brian Logan 2014 G52CON Lecture 1: Introduction 25

Assessment" Assessment is by examination: a two hour examination, worth 100% There are also several unassessed exercises. Brian Logan 2014 G52CON Lecture 1: Introduction 26

Reading list" Andrews (2000), Foundations of Multithreaded, Parallel and Distributed Programming, Addison Wesley. Lea (2000), Concurrent Programming in Java: Design Principles and Patterns, (2nd Edition), Addison Wesley. Ben-Ari (1982), Principles of Concurrent Programming, Prentice Hall. Andrews (1991), Concurrent Programming: Principles & Practice, Addison Wesley. Burns & Davis (1993), Concurrent Programming, Addison Wesley. Magee & Kramer (1999), Concurrency: State Models and Java Programs, John Wiley. Brian Logan 2014 G52CON Lecture 1: Introduction 27

The next lecture" Suggested reading for this lecture: Processes and Threads Andrews (2000), chapter 1, sections 1.1 1.2; Ben-Ari (1982), chapter 1. Suggested reading for the next lecture: Lea (2000), chapter 1. Java Tutorial, Threads docs.oracle.com/javase/tutorial/essential/concurrency Brian Logan 2014 G52CON Lecture 1: Introduction 28