1 / 11

Assignment 5 - FSP and Java

Assignment 5 - FSP and Java. The log-flume ride at a theme park operates as follows. This sequence is repeated forever. Once the log is empty it cleaned before riders can embark. Riders then embark one by one until the log is full.

waneta
Télécharger la présentation

Assignment 5 - FSP and Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assignment 5 - FSP and Java • The log-flume ride at a theme park operates as follows. This sequence is repeated forever. • Once the log is empty it cleaned before riders can embark. • Riders then embark one by one until the log is full. • The ride takes place and the log goes around the water track. • When the ride is over the riders disembark one by one. A sample trace is shown below to illustrate. Here the log has 2 seats and four potential riders, r[1..4].

  2. Assignment 5 - FSP and Java Complete the following FSP model of the log-flume ride for a log with 2 seats and four potential riders. set RIDERS = {r[1..4]} const SEATS = 2 LOG = (clean -> ride -> LOG). PASSENGER = (embark -> disembark -> PASSENGER). CONTROL = (..). ||LOGFLUME = (LOG ||RIDERS:PASSENGER ||RIDERS::CONTROL/{ride/RIDERS.ride,clean/RIDERS.clean}).

  3. Assignment 5 - FSP and Java 1. Solution set RIDERS = {r[1..4]} const SEATS = 2 LOG = (clean -> ride -> LOG). PASSENGER = (embark -> disembark -> PASSENGER). CONTROL = (clean -> ENTER[0]), ENTER [i:0..SEATS]= ( when (i<SEATS) embark -> ENTER[i+1] | when (i==SEATS) ride -> EXIT), EXIT = EXIT[SEATS], EXIT[i:1..SEATS] = ( when (i>1) disembark -> EXIT[i-1] | when (i==1) disembark -> CONTROL). ||LOGFLUME = (LOG || RIDERS:PASSENGER ||RIDERS::CONTROL/{ride/RIDERS.ride,clean/RIDERS.clean}).

  4. Assignment 5 - FSP and Java 2. Complete the Java template below thereby implementing the FSP model developed in (1). A sample output from the program is shown below:

  5. Assignment 5 - FSP and Java 2. Solution class Control { private int seats=2; private int spaces=2; private boolean rideFinished=false; private boolean cleaned=false; public synchronized void embark(int id){ while (spaces==0 || !cleaned) try {wait();} catch(InterruptedException e){} spaces--; System.out.println("rider."+id+" enters log "); notifyAll(); }

  6. Assignment 5 - FSP and Java 2. Solution public synchronized void disembark(int id){ while (!rideFinished) try {wait();} catch(InterruptedException e){} spaces++; rideFinished=true; System.out.println("rider."+id+" exits log"); notifyAll(); } public synchronized void clean(){ while (spaces!=seats) try {wait();} catch(InterruptedException e){} cleaned=true; rideFinished=false; System.out.println("\nLog cleaned"); notifyAll(); }

  7. Assignment 5 - FSP and Java 2. Solution public synchronized void ride(){ while (spaces!=0) try {wait();} catch(InterruptedException e){} rideFinished=true; cleaned=false; System.out.println("Ride finished"); notifyAll(); } }

  8. Assignment 5 - FSP and Java 4. To restore order on the log-flume ride the management installs a ticket machine that issues tickets to passengers. Tickets are numbered in the range 1..MT. When ticket MT has been issued the next ticket to be issued is ticket number 1. The log-flume controller only allows passengers to enter in ticket number order. Complete the following FSP model and show that even when their entry priority is low meek passengers will still get a ride.

  9. Assignment 5 - FSP and Java 4. continued set Bold = {bold[1..2]} set Meek = {meek[1..2]} set RIDERS = {Bold, Meek} const SEATS = 2 const MT=4 range T = 1..MT LOG = (clean -> ride -> LOG). PASSENGER = (ticket[t:T] -> embark[t] -> disembark -> PASSENGER). TICKET = .. CONTROL = (..). ||LOGFLUME = (LOG ||RIDERS:PASSENGER || RIDERS::TICKET ||RIDERS::CONTROL/{ride/RIDERS.ride,clean/RIDERS.clean}) >>{Meek.embark[T]}. progress BOLD = {Bold.embark[T]} progress MEEK = {Meek.embark[T]}

  10. Assignment 5 - FSP and Java 4. Solution set Bold = {bold[1..2]} set Meek = {meek[1..2]} set RIDERS = {Bold, Meek} const SEATS = 2 const MT=4 range T = 1..MT LOG = (clean -> ride -> LOG). PASSENGER = (ticket[t:T] -> embark[t] -> disembark -> PASSENGER). TICKET=TICKET[1], TICKET[t:T]=(ticket[t] -> TICKET[t%MT+1]).

  11. Assignment 5 - FSP and Java 4. Solution CONTROL = (clean -> ENTER[0][1]), ENTER [i:0..SEATS][t:T]= ( when (i<SEATS) embark[t] -> ENTER[i+1][t%MT+1] | when (i==SEATS) ride -> EXIT[SEATS][t]), EXIT[i:1..SEATS][t:T] = ( when (i>1) disembark -> EXIT[i-1][t] | when (i==1) disembark -> clean -> ENTER[0][t]). ||LOGFLUME = (LOG ||RIDERS:PASSENGER || RIDERS::TICKET ||RIDERS::CONTROL/{ride/RIDERS.ride,clean/RIDERS.clean}) >>{Meek.embark[T]}. progress BOLD = {Bold.embark[T]} progress MEEK = {Meek.embark[T]}

More Related