Concurrent Object Oriented Languages

Similar documents
5 Classical IPC Problems

Concept of a process

Process Synchronization

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Programming Languages

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

Process Management And Synchronization

Processes & Concurrency

Processes & Concurrency

CS3502 OPERATING SYSTEMS

PROCESS SYNCHRONIZATION

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

Process Synchronization. studykorner.org

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

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

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

4.5 Cigarette smokers problem

Lecture 3: Intro to Concurrent Processing using Semaphores

Introduction to Operating Systems

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

IV. Process Synchronisation

Process Synchronization

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

Midterm Exam. October 20th, Thursday NSC

OS Process Synchronization!

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

CSC501 Operating Systems Principles. Process Synchronization

CS370 Operating Systems

9/29/2014. CS341: Operating System Mid Semester Model Solution Uploaded Semaphore ADT: wait(), signal()

Programming Languages

Problem Set: Concurrency

Silberschatz and Galvin Chapter 6

Concurrency. Chapter 5

CSE 4/521 Introduction to Operating Systems

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

Operating Systems. Week 7 5 th Semester, 2012 IN Fei Peng PAI Group University of Fribourg

Interprocess Communication By: Kaushik Vaghani

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

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

Concurrency: a crash course

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Concurrency: Deadlock and Starvation. Chapter 6

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

Synchronization problems with semaphores

Process Synchronization

CONCURRENT/DISTRIBUTED PROGRAMMING ILLUSTRATED USING THE DINING PHILOSOPHERS PROBLEM *

Dealing with Issues for Interprocess Communication

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

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

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Concurrency EECS /36

Synchronization Principles II

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

Paralleland Distributed Programming. Concurrency

Dining Philosophers, Semaphores

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization

Chapter 7: Process Synchronization!

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

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

PESIT Bangalore South Campus

Lecture 10: Multi-Object Synchronization

The deadlock problem

Process Synchronization(2)

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

Process Coordination

Introduction to Linear-Time Temporal Logic. CSE 814 Introduction to LTL

Process Synchronization

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Process Synchronization(2)

The dining philosophers problem. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 13

Multicore and Multiprocessor Systems: Part I

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

EECS 482 Introduction to Operating Systems

Concurrent Processes Rab Nawaz Jadoon

Real-Time Operating Systems M. 5. Process Synchronization

Liveness properties. Deadlock

Lesson 6: Process Synchronization

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

Sections 01 (11:30), 02 (16:00), 03 (8:30) Ashraf Aboulnaga & Borzoo Bonakdarpour

Concurrent Programming TDA381/DIT390

CS370 Operating Systems

Background. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background

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

Semaphores (by Dijkstra)

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


CS 361 Concurrent programming Drexel University Spring 2000 Lecture 14. The dining philosophers problem

Deadlock and Monitors. CS439: Principles of Computer Systems February 7, 2018

Department of CSIT ( G G University, Bilaspur ) Model Answer 2013 (Even Semester) - AR-7307

Process Synchronization

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

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

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

Last Class: Monitors. Real-world Examples

2. The shared resource(s) in the dining philosophers problem is(are) a. forks. b. food. c. seats at a circular table.

CS370 Operating Systems

Basic Synchronization Principles

Transcription:

Concurrent Object Oriented Languages Semaphores wiki.eecs.yorku.ca/course/6490a

Semaphores A semaphore is a datatype. Its values are nonnegative integers. A semaphore, say s, supports two atomic operations: V(s): increment s by 1. P(s): decrement s by 1 as soon as the result is nonnegative.

Classical concurrency problems Using semaphores, we solve the following classical concurrency problems: The Producer-Consumer Problem (last lecture) The Readers-Writers Problem (already started last lecture) The Dining Philosophers Problem The Cigarette Smokers Problem

The Readers-Writers Problem The readers and writers problem, due to Courtois, Heymans and Parnas, is another classical concurrency problem. It models access to a database. There are many competing threads wishing to read from and write to the database. It is acceptable to have multiple threads reading at the same time, but if one thread is writing then no other thread may either read or write. The problem is how do you program the reader and writer threads?

David Parnas Canadian early pioneer of software engineering Ph.D. from Carnegie Mellon University Taught at the University of North Carolina at Chapel Hill, the Technische Universität Darmstadt, the University of Victoria, Queen s University, McMaster University, and University of Limerick Won numerous awards including ACM SIGSOFT s Outstanding Research award David Parnas source: Hubert Baumeister

Pierre-Jacques Courtois Professor emeritus at the Catholic University of Leuven Pierre-Jacques Courtois source: www.info.ucl.ac.be/~courtois

The Readers-Writers Problem The readers and writers share the following variable. semaphore mutex = 1; Reader: P( mutex ) ; read ; V( mutex ) ; Writer: P( mutex ) ; w r i t e ; V( mutex ) ;

The Readers-Writers Problem Does it solve the readers-writers problem?

The Readers-Writers Problem Does it solve the readers-writers problem? Answer Yes!

The Readers-Writers Problem Does it solve the readers-writers problem? Answer Yes! Is it a satisfactory solution?

The Readers-Writers Problem Does it solve the readers-writers problem? Answer Yes! Is it a satisfactory solution? Answer No!

The Readers-Writers Problem Why not?

The Readers-Writers Problem Why not? Answer It does not allow multiple readers to read at the same time.

The Readers-Writers Problem Options While a writer is writing, readers and writers arrive. Once the writer is done, can the readers start reading? Options While readers are reading, readers and writers arrive. Can the readers start reading?

The Readers-Writers Problem Options While a writer is writing, readers and writers arrive. Once the writer is done, can the readers start reading? Yes Options While readers are reading, readers and writers arrive. Can the readers start reading? Yes No reader is kept waiting unless a writer is writing.

The Readers-Writers Problem Options While a writer is writing, readers and writers arrive. Once the writer is done, can the readers start reading? Options While readers are reading, readers and writers arrive. Can the readers start reading?

The Readers-Writers Problem Options While a writer is writing, readers and writers arrive. Once the writer is done, can the readers start reading? No Options While readers are reading, readers and writers arrive. Can the readers start reading? No If a writer wants to write, it writes as soon as possible.

The Dining Philosophers Problem In the dining philosophers problem, due to Dijkstra, five philosophers are seated around a round table. Each philosopher has a plate of spaghetti. The spaghetti is so slippery that a philosopher needs two forks to eat it. The layout of the table is as follows. The life of a philosopher consists of alternative periods of eating and thinking. When philosophers get hungry, they try to pick up their left and right fork, one at a time, in either order. If successful in picking up both forks, the philosopher eats for a while, then puts down the forks and continues to think.

The Dining Philosophers Problem i n t N = 5; philosopher ( i ) : while ( t r u e ) t h i n k ; takeforks ( i ) ; eat ; putforks ( i ) ; takeforks ( i ) :... putforks ( i ) :...

The Dining Philosophers Problem i n t N = 5; semaphore mutex = 1; philosopher ( i ) : while ( t r u e ) t h i n k ; takeforks ( i ) ; eat ; putforks ( i ) ; takeforks ( i ) : P( mutex ) ; putforks ( i ) : V( mutex ) ;

The Dining Philosophers Problem Is this solution correct?

The Dining Philosophers Problem Is this solution correct? Answer Yes!

The Dining Philosophers Problem Is this solution correct? Answer Yes! Does this solution allow two philosophers to eat at the same time?

The Dining Philosophers Problem Is this solution correct? Answer Yes! Does this solution allow two philosophers to eat at the same time? Answer No!

The Cigarette Smokers Problem In the Cigarette Smokers Problem, due to Patil, there are an agent and three smokers. The smokers loop forever, first waiting for ingredients, then making and smoking cigarettes. The ingredients are tobacco, paper, and matches. We assume that the agent has an infinite supply of all three ingredients, and each smoker has an infinite supply of one of the ingredients; that is, one smoker has matches, another has paper, and the third has tobacco. The agent repeatedly chooses two different ingredients at random and makes them available to the smokers. Depending on which ingredients are chosen, the smoker with the complementary ingredient should pick up both resources and proceed. For example, if the agent puts out tobacco and paper, the smoker with the matches should pick up both ingredients, make a cigarette, and then signal the agent.

The Cigarette Smokers Problem Can we implement the random choices made by the agent using concurrency?

The Cigarette Smokers Problem Can we implement the random choices made by the agent using concurrency? Answer Yes, we can introduce a thread for each choice and run them concurrently.

The Cigarette Smokers Problem Can we implement the random choices made by the agent using concurrency? Answer Yes, we can introduce a thread for each choice and run them concurrently. How can we ensure that at most one of those threads executes at any time?

The Cigarette Smokers Problem Can we implement the random choices made by the agent using concurrency? Answer Yes, we can introduce a thread for each choice and run them concurrently. How can we ensure that at most one of those threads executes at any time? Answer Introduce a binary semaphore.

The Cigarette Smokers Problem Problem Use semaphores paper and tabacco for the agent who puts out tobacco and paper, signal the smoker with the matches.

The Cigarette Smokers Problem Shared variables semaphore agent = 1 semaphore match = 0 semaphore paper = 0 semaphore tabacco = 0 Agent (paper and tabacco): P( agent ) ; V( tabacco ) ; V( paper ) Agent (paper and matches): P( agent ) ; V( paper ) ; V( match ) Agent (tabacco and matches): P( agent ) ; V( tabacco ) ; V( match )

The Cigarette Smokers Problem Smoker (paper): P( tabacco ) ; P( match ) ; V( agent ) Smoker (matches): P( tabacco ) ; P( paper ) ; V( agent ) Smoker (tabacco): P( paper ) ; P( match ) ; V( agent )

The Cigarette Smokers Problem Is this solution correct?

The Cigarette Smokers Problem Is this solution correct? Answer No, because it can deadlock.