Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
1 of 1 
CSC321 Concurrent Programming 
 
Concurrent Programming 2005/06 
 
Assignment 5 – FSP and Java 
 
Please supply a printout of the source code for Q1, Q2 and Q4 and a 
copy of the source code on a disk or CD. 
 
1. 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 of 2 
Complete the following FSP model of the log-flume ride for a log with 2 
seats and four potential riders.  
. 
 
 
 
 
 
 
 
 
 
 
 
 
2. Complete the Java template below thereby implementing the FSP model 
developed in (1).  A sample output from the program is shown below: 
 
 
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 of 3 
 
 
import concurrent.*; 
class LogFlume { 
    public static void main (String[] args) { 
        int numberOfRiders=4; 
 
        Rider [] rider = new Rider[numberOfRiders]; 
        Control control = new Control(); 
        Log log = new Log(control); 
 
        for(int i=0; i ride -> LOG). 
PASSENGER = (embark -> disembark -> PASSENGER). 
 
CONTROL = (..). 
 
||LOGFLUME = (LOG ||RIDERS:PASSENGER 
||RIDERS::CONTROL/{ride/RIDERS.ride,clean/RIDERS.clean}) 
              >>{Meek.embark}. 
progress BOLD = {Bold.embark} 
progress MEEK = {Meek.embark} 
5 of 5 
 
 
 
 
 
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. As sample trace is 
shown on the next page. 
 
 
 
 
 
 
 
 
 
 
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]} 
6 of 6