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

Similar documents
Monitors & Condition Synchronization

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

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

CSCI 5828: Foundations of Software Engineering

CSCI 5828: Foundations of Software Engineering

Concurrent processes. Processes and Threads. Processes and threads. Going back to Concurrency. Modelling Processes. Modeling processes

Monitors & Condition Synchronization

Lecture 9: Introduction to Monitors

C340 Concurrency: Semaphores and Monitors. Goals

THE QUEEN S UNIVERSITY OF BELFAST

COMP31212: Concurrency A Review of Java Concurrency. Giles Reger

CONCURRENT PROGRAMMING - EXAM

Model Requirements and JAVA Programs MVP 2 1

COMP30112: Concurrency Topics 4.1: Concurrency Patterns - Monitors

Monitors & Condition Synchronization

Verification Finite-state process modeling and reachability analysis

COMP30112: Concurrency Topics 5.2: Properties

Concurrency: State Models & Design Patterns

CSCD 330 Network Programming

Monitors & Condition Synchronisation

Lecture 2: Modeling Introduction

Concurrency: State Models & Design Patterns

27/04/2012. We re going to build Multithreading Application. Objectives. MultiThreading. Multithreading Applications. What are Threads?

Concurrency in Java Prof. Stephen A. Edwards

COMPSCI 230 Threading Week8. Figure 1 Thread status diagram [

Chapter 6. Deadlock. DM519 Concurrent Programming

CSCD 330 Network Programming

Lecture 10: Introduction to Semaphores

Shared Objects & Mutual Exclusion

Safety & Liveness Properties

2. Concurrency and Java

Synchronization in Concurrent Programming. Amit Gupta

Need for synchronization: If threads comprise parts of our software systems, then they must communicate.

Contents. 6-1 Copyright (c) N. Afshartous

Synchronization in Java

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers

Synchronization

CMSC 132: Object-Oriented Programming II

G Programming Languages Spring 2010 Lecture 13. Robert Grimm, New York University

MCS-378 Intraterm Exam 1 Serial #:

Models of concurrency & synchronization algorithms

FSP Language Specification

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

CMSC 132: Object-Oriented Programming II. Threads in Java

MultiThreading 07/01/2013. Session objectives. Introduction. Introduction. Advanced Java Programming Course

Advanced Java Programming Course. MultiThreading. By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City

Lecture 7: Process & Thread Introduction

Week 7. Concurrent Programming: Thread Synchronization. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

CSCI 5828: Foundations of Software Engineering

CS18000: Programming I

CSCI 5828: Foundations of Software Engineering

3C03 Concurrency: Starvation and Deadlocks

Question Points Score Total 100

Module - 4 Multi-Threaded Programming

Reintroduction to Concurrency

Introduction to Java Threads

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

CS 556 Distributed Systems

COMP346 Winter Tutorial 4 Synchronization Semaphores

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

System Software Assignment 8 Deadlocks

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

public class Shared0 { private static int x = 0, y = 0;

Summary Semaphores. Passing the Baton any await statement. Synchronisation code not linked to the data

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages

$ Program Verification

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

Concurrency 6 - Deadlock

Question Points Score Total 100

Advanced Concepts of Programming

Formal modelling and verification in UPPAAL

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

Java Threads. Written by John Bell for CS 342, Spring 2018

re-exam Concurrent Programming tda383/dit390 Date: Time: 14:00 18:00 Place: Maskinhuset (M)

Animation Part 2: MoveableShape interface & Multithreading

Programming Language Concepts: Lecture 13

CSE 332: Locks and Deadlocks. Richard Anderson, Steve Seitz Winter 2014

Component-Based Software Engineering

Shared-Memory and Multithread Programming

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

Midterm #1. CMSC 433: Programming Language Technologies and Paradigms. October 14, 2013

Concurrency & Synchronization. COMPSCI210 Recitation 25th Feb 2013 Vamsi Thummala Slides adapted from Landon Cox

7. MULTITHREDED PROGRAMMING

Monitors; Software Transactional Memory

Concurrency - Topics. Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads

Monitors; Software Transactional Memory

Multi-threaded programming in Java

CSC 111, Test 1 (Fall 2009)

ECE 462 Exam 3. 11:30AM-12:20PM, November 17, 2010

How to Verify a CSP Model? February 28, 2009

A Sophomoric Introduction to Shared-Memory Parallelism and Concurrency Lecture 4 Shared-Memory Concurrency & Mutual Exclusion

107 學年度 (2018 年秋季班 ) 作業系統 學期群組計畫需求說明書

FAKULTÄT FÜR INFORMATIK

LTSA User Manual.

Lecture 10 State dependency

CSE332: Data Abstractions Lecture 22: Shared-Memory Concurrency and Mutual Exclusion. Tyler Robison Summer 2010

Concurrent Programming

Java Monitors. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

i219 Software Design Methodology 11. Software model checking Kazuhiro Ogata (JAIST) Outline of lecture

Transcription:

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 process then (x->p) describes a process that initially engages in the action x and then behaves exactly as described by P. ii. choice ( ) 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. [Subtotal 6 marks] b. For each of the following Labelled Transition Systems (LTS), give an equivalent FSP specification. i. ii. iii. LOCK a.lock a.unlock b.lock 0 1 2 b.unlock LOCK = (a.lock -> a.unlock -> LOCK b.lock -> b.unlock -> LOCK ). HOBSON choose -1 0 1 HOBSON RACE choose = (choose->stop choose->error). start finish fall 0 1 2 RACE = (start -> (fall->stop finish->race)). TURN OVER

2 iv. open 0 1 close close open DOOR = CLOSED, CLOSED = (close->closed open->opened), OPENED = (open ->OPENED close->closed). c. For each of the following FSP specifications, give an equivalent LTS. i. SQUARE = (in[i:1..2]->out[i*i]->square). SQUARE ii. CLOCK in.1 out.1 in.2 0 1 2 out.4 = CLOCK[0], CLOCK[i:0..4] = (when(i<4) tick->clock[i+1]). CLOCK tick tick tick tick 0 1 2 3 4 iii. DICE = (throw[i:1..6]->(when (i==6)again->dice)). DICE throw.6 throw.5 throw.4 throw.3 throw.2 throw.1 0 1 2 again [Subtotal 14 marks] CONTINUED

3 iv. ALICE = (start->alice.finish->alice). BOB = (start->bob.finish->bob). AB = (ALICE BOB). //draw LTS for AB only AB start bob.finish alice.finish 0 1 2 3 alice.finish bob.finish [Subtotal 14 marks] [Total 34 marks] TURN OVER

4 2. a. Briefly explain how a guarded action in an FSP specification is translated into part of a Java program that implements that specification. [10 marks] The basic format for modeling a guarded action for some condition cond and action act using FSP is shown below: FSP: when cond act -> NEWSTAT The corresponding format for implementing the guarded action for condition cond and action act using Java is as follows: Java: public synchronized void act() throws InterruptedException { while (!cond) wait(); // modify monitor data notifyall() b. In an automatic cable car system, each cable car has its own controller. The function of this controller is to ensure that a cable car only leaves the terminus when it is full of passengers. A cable car can hold a maximum of N passengers. After departure, the cable car arrives at the other end, all the passengers leave the cable car and new passengers may then board for another trip. The alphabet of the cable car is depicted below, together with a definition of the meaning of each action. board a passenger boards the cable car. cardepart the cable car departs. This action is delayed until the cable car is full. cararrive the cable car arrives at the other end. This action is delayed until after departure. Specify the behaviour of CABLECAR in FSP. CABLECAR(N=6) = PASSENGERS[0], PASSENGERS[i:0..N] = (when(i<n) board -> PASSENGERS[i+1] when(i==n)cardepart->trip ), TRIP = (cararrive -> disembark -> PASSENGERS[0]). [12 marks] CONTINUED

5 c. Implement the CABLECAR specification from part b with the above three actions as monitor methods programmed in Java. class CableCar { final int N = 6; int passengers = 0; bool departed = false; public synchronized void board() throws InterruptedException{ while(passengers==n) wait(); ++passengers; notifyall(); public synchronized void cardepart() throws InterruptedException{ while (passengers!=n departed) wait(); departed = true; public synchronized void cararrive() throws InterruptedException{ while (passengers!=n!departed) wait(); passengers=0; departed = false; notifyall(); [11 marks] [Total 33 marks] TURN OVER

6 3. a. Explain briefly how a resource, shared by a set of processes, can be modelled in FSP. [8 marks] {a1,..,ax::p replaces every label n in the alphabet of P with the labels a1.n,...,ax.n. Further, every transition (n->x) in the definition of P is replaced with the transitions ({a1.n,...,ax.n->x). Use this in: RESOURCE_SHARE=(a:USER b:user {a,b::resource). b. The cheese counter in a supermarket is continuously mobbed by hungry customers. To restore order, the management installs a ticket machine which issues tickets to customers. Tickets are numbered in the range 1..MT. When ticket MT has been issued, the next ticket to be issued will be ticket numbered 1, i.e. the management install a new ticket roll. The cheese counter has a display which indicates the ticket number of the customer currently being served. The customer with the ticket with the same number as the counter display then goes to the counter and is served. When the service is finished, the number is incremented (modulo MT). Given the structure diagram depicted below for the cheese counter system, specify the behaviour of each of the processes (CUSTOMER, TICKET, COUNTER) and the composite process CHEESE COUNTER in FSP. const MT = 4 //maximum ticket number const MC = 2 //number of customers range T = 1..MT range C = 1..MC CUSTOMER = (ticket[t:t]->getcheese[t]->customer). TICKET = TICKET[1], TICKET[t:T] = (ticket[t]->ticket[t%mt+1]). COUNTER = COUNTER[1], COUNTER[t:T] = (getcheese[t]->counter[t%mt+1]). [12 marks] CHEESE_COUNTER = (c[c]:customer {c[c]::ticket {c[c]::counter). CONTINUED

7 c. Implement the specifications for COUNTER and TICKET in Java. class Ticket { const MT = 1000; private int next = 0; public synchronized int ticket() { next = next%mt + 1; return next; class Counter { const MT = 1000; private int serve = 1; public synchronized getcheese(int ticket) throws Interruptedexception { while (ticket!=serve) wait(); serve = serve%mt + 1; notifyall(); [13 marks] [Total 33 marks] TURN OVER

8 4. a. i. Explain the terms safety property and liveness property with respect to concurrent programs. Safety Properties specify that nothing bad will happen. Liveness Properties determine that something good will eventually happen. ii. Draw the Labelled Transition System for the following safety property: property POLITE = (knock->enter->polite). enter knock knock -1 0 1 enter [Subtotal 8 marks] b. A lift has a maximum capacity of ten people. In the model of the lift control system, passengers entering a lift are signalled by an enter action and passengers leaving the lift are signalled by an exit action. Specify a safety property in FSP which when composed with the lift will check that the system never allows the lift that it controls to have more than ten occupants. property LIFT_TEN = LIFT[0], LIFT[i:0..10] = (when(i<10) enter -> LIFT[i+1] when(i>0) exit -> LIFT[i-1] when(i==0)exit -> LIFT[0] ). [8 marks] c. Explain what is meant by the term deadlock in the context of concurrent programs and explain how LTS models can be used to check for deadlock. [8 marks] Deadlock occurs in a system when all its constituent processes are blocked. Another way of saying this is that the system is deadlocked because there are no eligible actions that it can perform. In the finite state model of a process, a deadlocked state is simply a state with no outgoing transitions. A process in such a state can engage in no further actions. Analysis involves performing a complete search of the state space looking for such states. CONTINUED

9 d. It is possible for the following system to deadlock. Explain why this deadlock occurs. Alice = (call.bob -> wait.chris -> Alice). Bob = (call.chris -> wait.alice -> Bob). Chris = (call.alice -> wait.bob -> Chris). S = (Alice Bob Chris) /{call/wait. The following model attempts to fix the problem by allowing Alice, Bob and Chris to timeout from a call attempt. Is a deadlock still possible? If so describe how the deadlock can occur and give an execution trace leading to the deadlock. Alice = (call.bob -> wait.chris -> Alice Bob timeout.alice -> wait.chris ->Alice). = (call.chris -> wait.alice -> Bob timeout.bob -> wait.alice ->Bob). Chris = (call.alice -> wait.bob -> Chris timeout.chris -> wait.bob ->Chris). S = (Alice Bob Chris) /{call/wait. [9 marks] The first model deadlocks because each participant is trying to call someone who is trying to call someone else. Alice is trying to call Bob who is trying to call Chris who is trying to call Alice. A wait-for cycle exist. In the model with timeouts, exactly the same situation occurs after three consecutive timeouts since waits are renamed to be calls. Trace to DEADLOCK: timeout.alice timeout.bob timeout.chris [Total 33 marks] TURN OVER

10 5. a. Briefly outline the two different ways of creating a new thread in Java. class MyThread extends Thread {... Thread x = new MyThread(); class MyRun implements Runnable {... Thread x = new Thread(new MyRun()); [10 marks] b. A Special Savings Building Society Account is permitted to have a maximum balance of M hundred pounds. Savers may deposit one hundred pounds at a time into the account up to the maximum. They may withdraw money in multiple units of a hundred pounds so long as the account is not overdrawn. The alphabet of the process that models the savings account is depicted below, together with a definition of the meaning of each action. range T = 1..M deposit withdraw[t] deposit one hundred pounds. This action is blocked if the balance would exceed M. Specify the behaviour of ACCOUNT in FSP. const M = 6 range B = 0..M range T = 1..M ACCOUNT = BALANCE[0], BALANCE[b:B] = (when (b<m) deposit withdraw an amount in the range T hundred pounds. This action is blocked if sufficient funds are not available. [12 marks] -> BALANCE[b+1] when (b>0) withdraw[a:1..b] -> BALANCE[b-a] ). CONTINUED

11 c. Implement the ACCOUNT specification from part b with the two actions as monitor methods programmed in Java. class Account { int balance =0; int M; Account(int maximum) {M = maximum [11 marks] synchronized void deposit() throws InterruptedException { while (balance==m) wait(); ++balance; notifyall(); synchronized void withdraw(int amount) { throws InterruptedException { while (balance-amount<0) wait(); balance -= amount; notifyall(); [Total 33 marks] END OF PAPER