THE QUEEN S UNIVERSITY OF BELFAST

Size: px
Start display at page:

Download "THE QUEEN S UNIVERSITY OF BELFAST"

Transcription

1 THE QUEEN S UNIVERSITY OF BELFAST FSP Quick Reference Guide is attached to the end of the examination paper. 110CSC321 Level 3 EXAMINATION FOR THE DEGREE(S) OF MEng, BEng, BSc Concurrent Programming January 2003 Examiners: Professor R Pooley Professor NS Scott and the internal examiners All questions carry equal marks ANSWER 4 QUESTIONS

2 1. Java Monitors and FSP. (c) By considering the states that a Java thread can be in, describe with the aid of diagrams how mutual exclusion and synchronization are achieved in Java. [8 marks] What potential problem does the Java implementation of a monitor present to the programmer? How can this difficulty be avoided? [4 marks] Consider the following FSP specification. Person=( listen ->Person talk ->Person). LISTENER=(listen->LISTENER). SPEAKER =(talk->speaker). P=(a:LISTENER b:speaker {a,b::person). i. Draw the LTS graph for the composite process P. Give an example of a valid trace of P. ii. Processes LISTENER and SPEAKER are now replaced by LISTENER=(listen->LISTENER)+{talk. SPEAKER =(talk->speaker)+{listen. Draw the LTS graph for the modified composite process P. Give an example of a valid trace of P. Explain why the meaning of P has changed. [8 marks] 2 of 10

3 2. The Mutual Exclusion Problem. In the following attempted solution to the mutual exclusion problem the instructions 1b and 2b are atomic actions. Show that the algorithm can lead to starvation. int c=0; process P1 int L1 = 0; 1a: noncriticalsection1; do { 1b: <L1=c; c=1;> while (L1!= 0); 1c: criticalsection1; 1d: c = 0; end P1; process P2 int L2 = 0; 2a: noncriticalsection2; do { 2b: <L2=c; c=1;> while (L2!= 0); 2c: criticalsection2; 2d: c = 0; end P2; [4 marks] Consider the following attempted solution to the mutual exclusion problem Show that the algorithm does not satisfy the mutual exclusion property. int c1=1; int c2=1; process P1 1a: noncriticalsection1; 1b: c1=0; while (c2!=1) { 1c: c1=1; 1d: c1=0; 1e: criticalsection1; 1f: c1=1; end P1; process P2 2a: noncriticalsection2; 2b: c2=0; while (c1!=1) { 2c: c2=0; 2d: c2=1; 2e: criticalsection2; 2f: c2=1; end P2; (c) (d) [4 marks] Construct a Java solution to the mutual exclusion problem for 3 processes, p[0],p[1] and p[2], subject to the following constraints. i. The solution must be bare machine algorithm that does not use hardware assisted instructions. ii. It is guaranteed that no process will halt in its non-critical section i.e. starvation in the absence of contention is not an issue. iii. Process p[2] is first to enter its critical section. iv. When process p[i] leaves its critical section the next process to enter its critical section is p[(i+1)%3], where i=0,1,2. Prove that the program in (c) does not deadlock. 3 of 10

4 3. Semaphores. The Dining Philosophers problem can be specified as follows. "Five philosophers sit around a circular table. Each philosopher spends his life alternately thinking and eating. In the centre of the table is a large bowl of spaghetti. A philosopher needs two forks to eat a helping of spaghetti. One fork is placed between each pair of philosophers and they agree that each will only use the fork to their immediate right and left." i. Construct a semaphore solution to the Dining Philosophers problem that is correct in all respects except for the prevention of deadlock. ii. What are the four necessary and sufficient conditions for deadlock to occur? Show how each condition occurs in your semaphore solution. Suggest a strategy that will prevent deadlock. [12 marks] One proposed solution to the Dining Philosophers problem permits only four philosophers to sit down at the table at the same time. Two implementations are shown below. Assume in each a blocked-set semaphore implementation. i. Give an argument to show that in this implementation it is impossible to starve on the semaphore placesleft. Semaphore placesleft = new Semaphore(4); process Phil[i=0..4] P(placesLeft) eat think V(placesLeft) end Phil; [4 marks] ii. Show that in this implementation it is possible to starve on the semaphore placesleft. Semaphore placesleft = new Semaphore(4); Semaphore exit = new Semaphore(0); process Phil[i=0..4] P(placesLeft) eat think V(exit) end Phil; process Butler P(exit) V(placesLeft) end Butler; [4 marks] 4 of 10

5 4. Monitors. Hotel Ashoka has only one sauna for hotel guests. Any number of men can use the sauna at the same time and any number of women can use the sauna at the same time. However, men and women are not permitted to use it together. Consider the following Java monitor that is designed to solve the above problem. The class data nmen and nwomen record the number of men and the number of women in the sauna respectively. Complete the four monitor methods. Do not introduce any additional class data. class Sauna { private int nmen =0; private int nwomen =0; synchronized public void menenter() throws InterruptedException { synchronized public void menexit () { synchronized public void womenenter () throws InterruptedException { synchronized public void womenexit () { (c) Describe how your monitor works and explain why your solution is unfair. The class data in above is extended to include the following, private int waitingmen = 0; private int waitingwomen =0; private boolean mensturn=false; where waitingmen records the number of men who are waiting, waitingwomen records the number of women who are waiting and mensturn is a flag used to ensure fairness. Devise a fair solution that avoids deadlock. Explain how the solution works. Give the corresponding Java code for the menenter() and menexit() methods only. [8 marks] 5 of 10

6 5. Modelling Processes Using FSP. Consider the following problem. "A canyon cuts through the territory of a colony of baboons. The baboons use a rope stretching across the canyon to cross from one side to the other. The rope is strong enough to permit any number of baboons to cross in the same direction at the same time. However, the rope is too thin for the baboons to cross the canyon in both directions at the same time. " The activities of the baboons can be modelled using the FSP specification given below. Prefixes lr and rl refer to baboons moving left-right and right-left across the rope respectively. const N =.. range T = 0..N range ID = 1..N // baboon identities BABOON = (enter->exit->baboon). ENTER = C[1], C[i:ID] = ([i].enter-> C[i%N+1]). EXIT = C[1], C[i:ID] = ([i].exit-> C[i%N+1]). FIFO = ([ID]:BABOON ENTER EXIT). BABOONS = (lr:fifo rl:fifo). ROPE =. BaboonsCrossingCanyon = (BABOONS ROPE ONEWAY). property ONEWAY =. (c) For N = 2 draw the LTSA graph for the composite process FIFO. What effect do the processes ENTER and EXIT have on the actions of the baboons? Complete the FSP process ROPE so that baboons can move concurrently on the rope only if they are moving in the same direction. Explain how your process satisfies this requirement. Note: The issue of starvation should be ignored. Describe a safety property to check that left-right moving baboons do not collide with right-left moving baboons. Implement the check as a FSP safety property ONEWAY. If the ROPE constraint is removed, give an example of a trace that violates the safety property and explain how it would be detected by the LTSA tool as a safety violation. [8 marks] 6 of 10

7 6. FSP Models and their Java Implementation. A, S and J work in a bar. A washes the dirty glasses one at a time and places each on a workspace. The workspace can hold a maximum of 20 glasses. S and J remove the glasses from the workspace one at a time and dry them. [You can ignore what happens to a glass after it is dried.] Unfortunately, there is only one drying cloth so S and J have to take turns at using it. However, as J is able to dry faster he dries two glasses at each turn while S only dries one. S takes the first turn at drying. Model the concurrent activity in the bar using FSP. Your model should include the processes A,S J and WORKSPACE and use the alphabet {wash, sdry, jdry. [10 marks] Identify the passive process in your model and implement it as a Java monitor. [10 marks] 7 of 10

8 FSP Quick Reference 1. Processes A process is defined by one or more local processes separated by commas. The definition is terminated by a full stop. STOP and ERROR are primitive local processes. Example Process = (a -> Local), Local = (b -> STOP). Action Prefix -> Choice Guarded Action when Alphabet Extension + Table: 1 Process operators If x is an action and P a process then (x -> P) describes a process that initially engages in the action x and then behaves exactly as described by P. If x and y are actions then (x->p y->q) describes a process which initially engages in either of the actions x or y. After the first action has occurred, the subsequent behavior is described by P if the first action was x and Q if the first action was y. The choice (when B x -> P y -> Q) means that when the guard B is true then the actions x and y are both eligible to be chosen, otherwise if B is false then the action x cannot be chosen. The alphabet of a process is the set of actions in which it can engage. P + S extends the alphabet of the process P with the actions in the set S. 8 of 10

9 2. Composite Processes A composite process is the parallel composition of one or more processes. The definition of a composite process is preceded by. Example Composite = (P Q). Parallel Composition Replicator forall Process Labeling : Process Sharing :: Priority High << Priority Low >> Table 2: Composite Process Operators If P and Q are processes then (P Q) represents the concurrent execution of P and Q. forall [i:1..n] P(i) is the parallel composition (P(1) P(N)) a:p prefixes each label in the alphabet of P with a. {a1,..,ax::p replaces every label n in the alphabet of P with the labels a1.n,,ax.n. Further, every transition (n->q) in the definition of P is replaced with the transitions ({a1.n,,ax.n->q). C =(P Q)<<{a1,,an specifies a composition in which the actions a1,,an have higher priority than any other action in the alphabet of P Q including the silent action tau. In any choice in this system which has one or more of the actions a1,,an labelling a transition, the transitions labelled with lower priority actions are discarded. C=(P Q)>>{a1,,an specifies a composition in which the actions a1,,an have lower priority than any other action in the alphabet of P Q including the silent action tau. In any choice in this system which has one or more transitions not labeled by a1,,an, the transitions labeled by a1,,an are discarded. 9 of 10

10 3. Common Operators The operators in Table 3 may be used in the definition of both processes and composite processes. Conditional if then else Re-labeling / Hiding \ Table 3: Common Process Operators The process if B then P else Q behaves as the process P if the condition B is true otherwise it behaves as Q. If the else Q is omitted and B is false, then the process behaves as STOP. Re-labelling is applied to a process to change the names of action labels. The general form of re-labelling is: /{newlabel_1/oldlabel_1, newlabel_n/oldlabel_n. When applied to a process P, the hiding operator \{a1..ax removes the action names a1..ax from the alphabet of P and makes these concealed actions "silent". These silent actions are labelled tau. Silent actions in different processes are not shared. When applied to a process P, the interface hides all actions in the alphabet of P not labeled in the set a1..ax. 4. Properties Safety property Progress progress Table 4: Safety and Progress Properties A safety property P defines a deterministic process that asserts that any trace including actions in the alphabet of P, is accepted by P. progress P = {a1,a2..an defines a progress property P which asserts that in an infinite execution of a target system, at least one of the actions a1,a2..an will be executed infinitely often. 10 of 10

Deadlock. INF2140 Parallel Programming: Lecture 6. March 07, INF2140 Parallel Programming: Lecture 6 Deadlock

Deadlock. INF2140 Parallel Programming: Lecture 6. March 07, INF2140 Parallel Programming: Lecture 6 Deadlock March 07, 2012 Concepts System deadlock: no further progress Four necessary & sufficient conditions Models - no eligible actions Practice Blocked threads Aim: deadlock avoidance - to design systems where

More information

Safety & Liveness Properties

Safety & Liveness Properties March 14, 2012 safety & liveness properties Concepts properties: true for every possible execution safety: nothing bad happens liveness: something good eventually happens Models safety: progress: no reachable

More information

COMP 150-CCP Concurrent Programming. Lecture 12: Deadlock. Dr. Richard S. Hall

COMP 150-CCP Concurrent Programming. Lecture 12: Deadlock. Dr. Richard S. Hall COMP 150-CCP Concurrent Programming Lecture 12: Deadlock Dr. Richard S. Hall rickhall@cs.tufts.edu Concurrent programming February 28, 2008 Scenario Process 1 gets the lock for object A and wants to lock

More information

Deadlock. Concepts: Models: Practice: Aim: deadlock avoidance - to design systems where deadlock cannot occur. Chapter 6. Deadlock

Deadlock. Concepts: Models: Practice: Aim: deadlock avoidance - to design systems where deadlock cannot occur. Chapter 6. Deadlock Chapter 6 Deadlock Deadlock Concepts: Models: Practice: system deadlock: no further progress four necessary & sufficient conditions deadlock - no eligible actions blocked threads Aim: deadlock avoidance

More information

Concurrency: Deadlock 1. Magee/Kramer 2 nd Edition

Concurrency: Deadlock 1. Magee/Kramer 2 nd Edition Concurrency: Deadlock 1 Concurrency: Deadlock 2 Chapter 6 Deadlock Concurrency: Deadlock 3 Deadlock Concepts: system deadlock: no further progress four necessary & sufficient conditions Models: deadlock

More information

Chapter 6. Deadlock Concurrency: Deadlock. Magee/Kramer 2 nd Edition

Chapter 6. Deadlock Concurrency: Deadlock. Magee/Kramer 2 nd Edition Chapter 6 Deadlock 1 Deadlock Concepts: Models: system deadlock: no further progress four necessary & sufficient conditions deadlock - no eligible actions Practice: blocked threads Aim: deadlock avoidance

More information

Chapter 6. Deadlock. DM519 Concurrent Programming

Chapter 6. Deadlock. DM519 Concurrent Programming Chapter 6 Deadlock 1 But First: Repetition Monitors and Condition Synchronisation 2 Monitors & Condition Synchronisation Concepts: monitors: Models: encapsulated data + access procedures + mutual exclusion

More information

Resource Allocation - Dining Philosophers. Dining Philosophers - Properties. OK? EATING[(i%N)+1]) Impossibility Result for Symmetric Algorithm

Resource Allocation - Dining Philosophers. Dining Philosophers - Properties. OK? EATING[(i%N)+1]) Impossibility Result for Symmetric Algorithm Resource Allocation - Dining Philosophers Dining Philosophers - Properties Five philosophers sit around a circular table. Each philosopher spends his life alternately thinking and eating. In the centre

More information

COMP30112: Concurrency Topics 5.2: Properties

COMP30112: Concurrency Topics 5.2: Properties COMP30112: Concurrency Topics 5.2: Properties Howard Barringer Room KB2.20: email: Howard.Barringer@manchester.ac.uk April 2008 Outline Topic 5.2: Properties Properties in general Specifying Safety Properties

More information

Process Management And Synchronization

Process Management And Synchronization Process Management And Synchronization In a single processor multiprogramming system the processor switches between the various jobs until to finish the execution of all jobs. These jobs will share the

More information

Lecture 3: Intro to Concurrent Processing using Semaphores

Lecture 3: Intro to Concurrent Processing using Semaphores Lecture 3: Intro to Concurrent Processing using Semaphores Semaphores; The Prucer-Consumer problem; The Dining Philosophers problem; The Readers-Writers Problem: Readers Preference Passing the Baton Ballhausen

More information

3C03 Concurrency: Starvation and Deadlocks

3C03 Concurrency: Starvation and Deadlocks 3C03 Concurrency: Starvation and Deadlocks Wolfgang Emmerich 1 Goals Reader/Writer problem Starvation Dining Philosophers Problem Deadlocks Liveness Analysis using LTS 2 1 Reader / Writer Problem Monitors

More information

SFDV3006 Concurrent Programming

SFDV3006 Concurrent Programming SFDV3006 Concurrent Programming Lecture 6 Deadlocks, livelocks, Starvation Introduction Last week we covered semaphore and how to use them for both synchronization and condition synchronization This week

More information

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

Contribution:javaMultithreading Multithreading Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team http://101companies.org/wiki/ Contribution:javaMultithreading Multithreading Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team Non-101samples available here: https://github.com/101companies/101repo/tree/master/technologies/java_platform/samples/javathreadssamples

More information

Concurrency: State Models & Design Patterns

Concurrency: State Models & Design Patterns Concurrency: State Models & Design Patterns Practical Session Week 02 1 / 13 Exercises 01 Discussion Exercise 01 - Task 1 a) Do recent central processing units (CPUs) of desktop PCs support concurrency?

More information

Concurrency: State Models & Design Patterns

Concurrency: State Models & Design Patterns Concurrency: State Models & Design Patterns Practical Session Week 05 1 / 13 Exercises 04 Discussion Exercise 04 - Task 1 a) Why are immutable classes inherently safe? Because the state of an instance

More information

Interprocess Communication By: Kaushik Vaghani

Interprocess Communication By: Kaushik Vaghani Interprocess Communication By: Kaushik Vaghani Background Race Condition: A situation where several processes access and manipulate the same data concurrently and the outcome of execution depends on the

More information

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems Synchronization CS 475, Spring 2018 Concurrent & Distributed Systems Review: Threads: Memory View code heap data files code heap data files stack stack stack stack m1 m1 a1 b1 m2 m2 a2 b2 m3 m3 a3 m4 m4

More information

Answer the first question and two further questions. i. action prefix ( -> ) [3 marks]

Answer the first question and two further questions. i. action prefix ( -> ) [3 marks] 1 Answer the first question and two further questions. 1. a. Define the meaning of the following constructs of the Finite State Process (FSP) notation. i. action prefix ( -> ) If x is an action and P a

More information

Paralleland Distributed Programming. Concurrency

Paralleland Distributed Programming. Concurrency Paralleland Distributed Programming Concurrency Concurrency problems race condition synchronization hardware (eg matrix PCs) software (barrier, critical section, atomic operations) mutual exclusion critical

More information

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

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28) Lecture Topics Today: Concurrency (Stallings, chapter 5.1-5.4, 5.7) Next: Exam #1 1 Announcements Self-Study Exercise #5 Project #3 (due 9/28) Project #4 (due 10/12) 2 Exam #1 Tuesday, 10/3 during lecture

More information

5. Liveness and Guarded Methods

5. Liveness and Guarded Methods 5. Liveness and Guarded Methods Prof. O. Nierstrasz Selected material Magee and Kramer Roadmap > Liveness Progress Properties > Deadlock The Dining Philosophers problem Detecting and avoiding deadlock

More information

Chapter 9. Labelled Transition Systems. System Composition. specifications. implementations.

Chapter 9. Labelled Transition Systems. System Composition. specifications. implementations. SFWR ENG 3BB4 Software Design 3 Concurrent System Design SFWR ENG 3BB4 Software Design 3 Concurrent System Design 9.9 System Composition Chapter 9 Labelled Transition Systems A system specification is

More information

Lecture 27: Safety and Liveness Properties, Java Synchronizers, Dining Philosophers Problem

Lecture 27: Safety and Liveness Properties, Java Synchronizers, Dining Philosophers Problem COMP 322: Fundamentals of Parallel Programming Lecture 27: Safety and Liveness Properties, Java Synchronizers, Dining Philosophers Problem Mack Joyner and Zoran Budimlić {mjoyner, zoran}@rice.edu http://comp322.rice.edu

More information

FSP Language Specification

FSP Language Specification FSP Language Specification V2.0 additions 1 V2.0 -Additions FSP Language Specification This document describes the additions that have been made to the FSP input notation to the LTSA tool since its initial

More information

Models of concurrency & synchronization algorithms

Models of concurrency & synchronization algorithms Models of concurrency & synchronization algorithms Lecture 3 of TDA383/DIT390 (Concurrent Programming) Carlo A. Furia Chalmers University of Technology University of Gothenburg SP3 2016/2017 Today s menu

More information

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems : Organization of Programming Languages Threads Classic Concurrency Problems The Dining Philosophers Problem Philosophers either eat or think They must have two forks to eat Can only use forks on either

More information

C340 Concurrency: Semaphores and Monitors. Goals

C340 Concurrency: Semaphores and Monitors. Goals C340 Concurrency: Semaphores and Monitors Wolfgang Emmerich 1 Goals Introduce concepts of Semaphores Monitors Implementation in Java synchronised methods and private attributes single thread active in

More information

Process Synchronization

Process Synchronization CSC 4103 - Operating Systems Spring 2007 Lecture - VI Process Synchronization Tevfik Koşar Louisiana State University February 6 th, 2007 1 Roadmap Process Synchronization The Critical-Section Problem

More information

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

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference

More information

Concurrency 6 - Deadlock

Concurrency 6 - Deadlock Concurrency 6 - Deadlock Monitors & Condition Synchronization - Repetition!!"! "#$! %!#$ &' (&') #&' #&' # wait(), notify(), and notifyall() - Repetition public final void wait() throws InterruptedException;

More information

Resource management. Real-Time Systems. Resource management. Resource management

Resource management. Real-Time Systems. Resource management. Resource management Real-Time Systems Specification Implementation Verification Mutual exclusion is a general problem that exists at several levels in a real-time system. Shared resources internal to the the run-time system:

More information

Lecture 10: Introduction to Semaphores

Lecture 10: Introduction to Semaphores COMP 150-CCP Concurrent Programming Lecture 10: Introduction to Semaphores Dr. Richard S. Hall rickhall@cs.tufts.edu Concurrent programming February 19, 2008 Semaphores Semaphores (Dijkstra 1968) are widely

More information

Concurrency: Mutual Exclusion and Synchronization. Concurrency

Concurrency: Mutual Exclusion and Synchronization. Concurrency Concurrency: Mutual Exclusion and Synchronization Chapter 5 1 Concurrency Multiple applications Structured applications Operating system structure 2 1 Concurrency 3 Difficulties of Concurrency Sharing

More information

Monitors & Condition Synchronization

Monitors & Condition Synchronization Feb. 15, 2012 Monitors & condition Synchronization Concepts: monitors: encapsulated data + access procedures mutual exclusion + condition synchronization single access procedure active in the monitor Models:

More information

Process Synchronization

Process Synchronization CS307 Process Synchronization Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2018 Background Concurrent access to shared data may result in data inconsistency

More information

Real-Time Systems. Lecture #4. Professor Jan Jonsson. Department of Computer Science and Engineering Chalmers University of Technology

Real-Time Systems. Lecture #4. Professor Jan Jonsson. Department of Computer Science and Engineering Chalmers University of Technology Real-Time Systems Lecture #4 Professor Jan Jonsson Department of Computer Science and Engineering Chalmers University of Technology Real-Time Systems Specification Resource management Mutual exclusion

More information

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

Introduction to Linear-Time Temporal Logic. CSE 814 Introduction to LTL Introduction to Linear-Time Temporal Logic CSE 814 Introduction to LTL 1 Outline Motivation for TL in general Types of properties to be expressed in TL Structures on which LTL formulas are evaluated Syntax

More information

CSCI 5828: Foundations of Software Engineering

CSCI 5828: Foundations of Software Engineering CSCI 5828: Foundations of Software Engineering Lecture 16: Monitors & Condition Synchronization Slides created by Magee and Kramer for the Concurrency textbook 1 Chapter 5 Monitors & Condition Synchronization

More information

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages The Dining Philosophers Problem CMSC 0: Organization of Programming Languages Threads Classic Concurrency Problems Philosophers either eat or think They must have two forks to eat Can only use forks on

More information

CSC501 Operating Systems Principles. Process Synchronization

CSC501 Operating Systems Principles. Process Synchronization CSC501 Operating Systems Principles Process Synchronization 1 Last Lecture q Process Scheduling Question I: Within one second, how many times the timer interrupt will occur? Question II: Within one second,

More information

Monitors & Condition Synchronization

Monitors & Condition Synchronization Chapter 5 Monitors & Condition Synchronization monitors & condition synchronization Concepts: monitors: encapsulated data + access procedures mutual exclusion + condition synchronization single access

More information

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

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - XI Deadlocks - II. Louisiana State University CSC 4103 - Operating Systems Fall 2009 Lecture - XI Deadlocks - II Tevfik Ko!ar Louisiana State University September 29 th, 2009 1 Roadmap Classic Problems of Synchronization Bounded Buffer Readers-Writers

More information

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

Roadmap. Bounded-Buffer Problem. Classical Problems of Synchronization. Bounded Buffer 1 Semaphore Soln. Bounded Buffer 1 Semaphore Soln. Tevfik Ko! CSC 4103 - Operating Systems Fall 2009 Lecture - XI Deadlocks - II Roadmap Classic Problems of Synchronization Bounded Buffer Readers-Writers Dining Philosophers Sleeping Barber Deadlock Prevention Tevfik

More information

CMSC 330: Organization of Programming Languages. The Dining Philosophers Problem

CMSC 330: Organization of Programming Languages. The Dining Philosophers Problem CMSC 330: Organization of Programming Languages Threads Classic Concurrency Problems The Dining Philosophers Problem Philosophers either eat or think They must have two forks to eat Can only use forks

More information

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3 Operating Systems Antonio Vivace - 2016 revision 4 Licensed under GPLv3 Process Synchronization Background A cooperating process can share directly a logical address space (code, data) or share data through

More information

Verification Finite-state process modeling and reachability analysis

Verification Finite-state process modeling and reachability analysis Verification Finite-state process modeling and reachability analysis Topics: Finite-state process modeling Verification through interactive simulation Concurrent composition of processes Verification through

More information

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

Multithreaded Programming Part II. CSE 219 Stony Brook University, Department of Computer Science Multithreaded Programming Part II CSE 219 Stony Brook University, Thread Scheduling In a Java application, main is a thread on its own Once multiple threads are made Runnable the thread scheduler of the

More information

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University Frequently asked questions from the previous class survey CS 370: SYSTEM ARCHITECTURE & SOFTWARE [PROCESS SYNCHRONIZATION] Shrideep Pallickara Computer Science Colorado State University Semaphores From

More information

Synchronized Methods of Old Versions of Java

Synchronized Methods of Old Versions of Java Administrivia Assignment #4 is out Due Thursday April 8, 10:00pm no late assignments will be accepted Sign up in labs next week for a demo time In case you hadn t noticed Classes end Thursday April 15

More information

More Synchronization; Concurrency in Java. CS 475, Spring 2018 Concurrent & Distributed Systems

More Synchronization; Concurrency in Java. CS 475, Spring 2018 Concurrent & Distributed Systems More Synchronization; Concurrency in Java CS 475, Spring 2018 Concurrent & Distributed Systems Review: Semaphores Synchronization tool that provides more sophisticated ways (than Mutex locks) for process

More information

Shared Objects & Mutual Exclusion

Shared Objects & Mutual Exclusion Feb. 08, 2012 Concurrent Execution Concepts Process interference Mutual exclusion Models Model checking for interference Modeling mutual exclusion Practice Multithreaded Java programs Thread interference

More information

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

Roadmap. Readers-Writers Problem. Readers-Writers Problem. Readers-Writers Problem (Cont.) Dining Philosophers Problem. CSE 421/521 - Operating Systems Fall 2011 Lecture - X Process Synchronization & Deadlocks Roadmap Classic Problems of Synchronization Readers and Writers Problem Dining-Philosophers Problem Sleeping Barber

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Objectives Introduce Concept of Critical-Section Problem Hardware and Software Solutions of Critical-Section Problem Concept of Atomic Transaction Operating Systems CS

More information

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock Deadlock in Resource Sharing Environment Operating System Deadlocks CIT 595 Spring 2010 A deadlock occurs when 2 or more processes/threads permanently block each other by each having a lock on a resource

More information

System Software Assignment 8 Deadlocks

System Software Assignment 8 Deadlocks System Software Assignment 8 Deadlocks Exercise 1: Barrier Objects Create a barrier object in Java, Active Oberon or the language of your choice that is able to synchronize a set of predefined threads

More information

CHAPTER 6: PROCESS SYNCHRONIZATION

CHAPTER 6: PROCESS SYNCHRONIZATION CHAPTER 6: PROCESS SYNCHRONIZATION The slides do not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. TOPICS Background

More information

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

Chapter 6: Synchronization. Operating System Concepts 8 th Edition, Chapter 6: Synchronization, Silberschatz, Galvin and Gagne 2009 Outline Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization

More information

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

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem? What is the Race Condition? And what is its solution? Race Condition: Where several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 12 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ 2 Mutex vs Semaphore Mutex is binary,

More information

Pre- and post- CS protocols. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 7. Other requirements for a mutual exclusion algorithm

Pre- and post- CS protocols. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 7. Other requirements for a mutual exclusion algorithm CS 361 Concurrent programming Drexel University Fall 2004 Lecture 7 Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce

More information

PROCESS SYNCHRONIZATION

PROCESS SYNCHRONIZATION PROCESS SYNCHRONIZATION Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization Monitors Synchronization

More information

[module 2.2] MODELING CONCURRENT PROGRAM EXECUTION

[module 2.2] MODELING CONCURRENT PROGRAM EXECUTION v1.0 20130407 Programmazione Avanzata e Paradigmi Ingegneria e Scienze Informatiche - UNIBO a.a 2013/2014 Lecturer: Alessandro Ricci [module 2.2] MODELING CONCURRENT PROGRAM EXECUTION 1 SUMMARY Making

More information

CSCI 5828: Foundations of Software Engineering

CSCI 5828: Foundations of Software Engineering CSCI 5828: Foundations of Software Engineering Lecture 7: Concurrent Execution Slides created by Magee and Kramer for the Concurrency textbook 2/05/2008 1 Magee/Kramer 2nd Edition What s the Difference?

More information

Process Synchronization

Process Synchronization TDDI04 Concurrent Programming, Operating Systems, and Real-time Operating Systems Process Synchronization [SGG7] Chapter 6 Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin

More information

CSCI 5828: Foundations of Software Engineering

CSCI 5828: Foundations of Software Engineering CSCI 5828: Foundations of Software Engineering Lecture 7: Concurrent Execution Slides created by Magee and Kramer for the Concurrency textbook 1 Magee/Kramer 2nd Edition Chapter 3 Concurrent Execution

More information

Lecture 2: Intro to Concurrent Processing

Lecture 2: Intro to Concurrent Processing Lecture 2: Intro to Concurrent Processing The SR Language. Correctness and Concurrency. Mutual Exclusion & Critical Sections. Software Solutions to Mutual Exclusion. Dekker s Algorithm. The Bakery Algorithm.

More information

Midterm Exam Amy Murphy 19 March 2003

Midterm Exam Amy Murphy 19 March 2003 University of Rochester Midterm Exam Amy Murphy 19 March 2003 Computer Systems (CSC2/456) Read before beginning: Please write clearly. Illegible answers cannot be graded. Be sure to identify all of your

More information

Ch 9: Control flow. Sequencers. Jumps. Jumps

Ch 9: Control flow. Sequencers. Jumps. Jumps Ch 9: Control flow Sequencers We will study a number of alternatives traditional sequencers: sequential conditional iterative jumps, low-level sequencers to transfer control escapes, sequencers to transfer

More information

Reintroduction to Concurrency

Reintroduction to Concurrency Reintroduction to Concurrency The execution of a concurrent program consists of multiple processes active at the same time. 9/25/14 7 Dining philosophers problem Each philosopher spends some time thinking

More information

Process Synchronization

Process Synchronization Chapter 7 Process Synchronization 1 Chapter s Content Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors 2 Background

More information

Concurrency & Parallelism. Threads, Concurrency, and Parallelism. Multicore Processors 11/7/17

Concurrency & Parallelism. Threads, Concurrency, and Parallelism. Multicore Processors 11/7/17 Concurrency & Parallelism So far, our programs have been sequential: they do one thing after another, one thing at a. Let s start writing programs that do more than one thing at at a. Threads, Concurrency,

More information

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1 Deadlock Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1 Recap: Synchronization Race condition A situation when two or more threads read and write shared

More information

Threads, Concurrency, and Parallelism

Threads, Concurrency, and Parallelism Threads, Concurrency, and Parallelism Lecture 24 CS2110 Spring 2017 Concurrency & Parallelism So far, our programs have been sequential: they do one thing after another, one thing at a time. Let s start

More information

sample exam Concurrent Programming tda383/dit390 Sample exam March 2016 Time:?? Place: Johanneberg

sample exam Concurrent Programming tda383/dit390 Sample exam March 2016 Time:?? Place: Johanneberg sample exam Concurrent Programming tda383/dit390 Sample exam March 2016 Time:?? Place: Johanneberg Responsible Michał Pałka 0707966066 Result Available no later than?-?-2016 Aids Max 2 books and max 4

More information

The Drinking Philosophers Problem-1

The Drinking Philosophers Problem-1 The Drinking Philosophers Problem The classical Dining Philosophers Problem problem synchronization among competing processes five philosophers (thinking, hungry, and eating) around a table five chopsticks

More information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 11: Semaphores I" Brian Logan School of Computer Science bsl@cs.nott.ac.uk Outline of this lecture" problems with Peterson s algorithm semaphores implementing semaphores

More information

Concurrency: Deadlock and Starvation. Chapter 6

Concurrency: Deadlock and Starvation. Chapter 6 Concurrency: Deadlock and Starvation Chapter 6 Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involve conflicting needs for resources

More information

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

CS 361 Concurrent programming Drexel University Spring 2000 Lecture 14. The dining philosophers problem CS 361 Concurrent programming Drexel University Spring 2000 Lecture 14 Bruce Char. All rights reserved by the author. Permission is given to students enrolled in CS361 Spring 2000 to reproduce these notes

More information

Chapter 7: Process Synchronization!

Chapter 7: Process Synchronization! Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Monitors 7.1 Background Concurrent access to shared

More information

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution Race Condition Synchronization CSCI 315 Operating Systems Design Department of Computer Science A race occurs when the correctness of a program depends on one thread reaching point x in its control flow

More information

Verification of Java programs using networks of finite automata with discrete data.

Verification of Java programs using networks of finite automata with discrete data. Catholic University in Ružomberok Scientific Issues, Mathematica II, Ružomberok 2009 Verification of Java programs using networks of finite automata with discrete data. Bożena Woźna, Andrzej Zbrzezny Institute

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST II Date: 04/04/2018 Max Marks: 40 Subject & Code: Operating Systems 15CS64 Semester: VI (A & B) Name of the faculty: Mrs.Sharmila Banu.A Time: 8.30 am 10.00 am Answer any FIVE

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - XXVI April 27 th, 2006 1 Roadmap Shared Memory Synchronization Spin Locks Barriers Semaphores Monitors 2 1 Memory Architectures Distributed Memory Shared Memory

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 11 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel Feedback Queue: Q0, Q1,

More information

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

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6. Part Three - Process Coordination Chapter 6: Synchronization 6.1 Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure

More information

Process Synchronization

Process Synchronization Process Synchronization Concurrent access to shared data in the data section of a multi-thread process, in the shared memory of multiple processes, or in a shared file Although every example in this chapter

More information

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources Concurrency: Deadlock and Starvation Chapter 6 Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other No efficient solution Involve conflicting

More information

COMP 322: Fundamentals of Parallel Programming. Lecture 30: Java Synchronizers, Dining Philosophers Problem

COMP 322: Fundamentals of Parallel Programming. Lecture 30: Java Synchronizers, Dining Philosophers Problem COMP 322: Fundamentals of Parallel Programming Lecture 30: Java Synchronizers, Dining Philosophers Problem Vivek Sarkar, Shams Imam Department of Computer Science, Rice University Contact email: vsarkar@rice.edu,

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Chapter 6: Synchronization 6.1 Background 6.2 The Critical-Section Problem 6.3 Peterson s Solution 6.4 Synchronization Hardware 6.5 Mutex Locks 6.6 Semaphores 6.7 Classic

More information

Processes & Threads. Concepts: processes - units of sequential execution.

Processes & Threads. Concepts: processes - units of sequential execution. Chapter 2 Processes & Threads concurrent processes We structure complex systems as sets of simpler activities, each represented as a sequential process. Processes can overlap or be concurrent, so as to

More information

Chapter 2. Processes & Threads. Concurrency: processes & threads 1. Magee/Kramer

Chapter 2. Processes & Threads. Concurrency: processes & threads 1. Magee/Kramer Chapter 2 Processes & Threads Concurrency: processes & threads 1 concurrent processes We structure complex systems as sets of simpler activities, each represented as a sequential process. Processes can

More information

Chapter 7: Process Synchronization. Background. Illustration

Chapter 7: Process Synchronization. Background. Illustration Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 1018 L11 Synchronization Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel feedback queue:

More information

LTSA User Manual.

LTSA User Manual. LTSA User Manual www.doc.ic.ac.uk/~jnm/book/firstbook/ltsa/ltsa-doc/usermanual.html User manual It is the hope of the designers of LTSA that this manual should be largely unnecessary. In most cases, the

More information

CSCI 5828: Foundations of Software Engineering

CSCI 5828: Foundations of Software Engineering CSCI 5828: Foundations of Software Engineering Lecture 4: Processes and Threads Slides created by Magee and Kramer for the Concurrency textbook 01/24/2008 1 Magee/Kramer 2nd Edition Chapter 2 Processes

More information

The concept of concurrency is fundamental to all these areas.

The concept of concurrency is fundamental to all these areas. Chapter 5 Concurrency(I) The central themes of OS are all concerned with the management of processes and threads: such as multiprogramming, multiprocessing, and distributed processing. The concept of concurrency

More information

Lesson 6: Process Synchronization

Lesson 6: Process Synchronization Lesson 6: Process Synchronization Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization

More information

7. Testing and Debugging Concurrent Programs

7. Testing and Debugging Concurrent Programs 7. Testing and Debugging Concurrent Programs The purpose of testing is to find program failures => A successful test is a test that causes a program to fail. Ideally, tests are designed before the program

More information