Finally getting into concurrent programming but it's not easy for the novice like me, after all this work I still cannot get a successful compilation!!!
A simple roundabout (traffic circle) is a circular junction of four streets where traffic flows in a one-way and one-lane circular stream around a central island, cars can enter, travel around and leave the roudabout. A car joining the roundabout must first make sure the slot ahead and the slot to the right of them is free. It then moves around until it is opposite the desired exit slot. It then moves off the roundabout unhindered.To avoid car crashes only one car at a time can be in any of the available slots. Cars can enter from any of the four directions and leave from any of the exits. Additionally to avoid overcrowding(and possible deadlock!) a maximum of six cars is allowed on to the roundabout at any time! tricky is it not? lol.
This is the result of a weeks work below!
package roundabout;
public class roundabout01
{
Process main;
{
/* declare and initialize global variables */
int NUMBER_OF_CARS = 20;
int numberOnRoundabout = 0;
/* slots on the roundabout */
String slots [] = {"[.....]", "[.....]", "[.....]", "[.....]", "[.....]", "[.....]", "[.....]", "[.....]"};
/* create and set the cars moving */
for (int count = 1; NUMBER_OF_CARS < 6; count++);
{
int entry = 3;
int exit = 3;
carProcess(entry, exit);
// end for; /*end main process*/
}
Process carProcess (int s, int t);
{
<await((numberOnRoundabout<=6), numberOnRoundabout++)>; /* Wait if roundabout crowded*/
/* wait for clearance before moving on to the roundabout */
<await(slots[2..s]=="[.....]"); AND (slots[2..s + 7] mod 8 == "[.....]");
slots[2..s]="["+entry+"-->"+exit+"]";
int currentPosition = 2*s;
int nextPosition = 2*s+1; /* move around to exit position (which is 2t) */
}
do
{
<await(slots[nextPosition]="[.....]");
slots[nextPosition]=slots[currentPosition];
slots[currentPosition]="[.....]">
currentPosition != nextPosition;
nextPosition = (nextPosition + 1) mod 8;
}
while (currentPosition != 2*t);
{
slots[currentPosition]="[.....]";
numberOnRoundabout -- ; /* move off the roundabout */
End carProcess;
}
}
}
This is the full list of errors, I've managed to get only a few of them!
Description Resource Path Location Type
Syntax error on token ",", ; expected roundabout01.java /concurrent systems/src/roundabout line 26 Java Problem
Syntax error on token ";", invalid Expression roundabout01.java /concurrent systems/src/roundabout line 29 Java Problem
Syntax error on token "(", ; expected roundabout01.java /concurrent systems/src/roundabout line 26 Java Problem
Syntax error on token ")", ; expected roundabout01.java /concurrent systems/src/roundabout line 26 Java Problem
Syntax error on token "<", delete this token roundabout01.java /concurrent systems/src/roundabout line 42 Java Problem
Syntax error on token "<", throw expected roundabout01.java /concurrent systems/src/roundabout line 29 Java Problem
Syntax error on token "=", != expected roundabout01.java /concurrent systems/src/roundabout line 44 Java Problem
Syntax error on token "MOD", , expected roundabout01.java /concurrent systems/src/roundabout line 33 Java Problem
Syntax error on token "MOD", invalid AssignmentOperator roundabout01.java /concurrent systems/src/roundabout line 45 Java Problem
The method carProcess(int, int) is undefined for the type roundabout01 roundabout01.java /concurrent systems/src/roundabout line 21 Java Problem