私たちの講師から出された質問があります。ラウンドアバウトが渋滞しないように、ラウンドアバウトに入るのを待っている車のことです。彼はおそらく、「await( BS)」ステートメントを使用してこれを解決する方法を提供し、セマフォを使用するように変換するように依頼しましたが、彼が提供したコードは lol を計算しません。彼が何をしていたのかはわかりませんが、Java では意味がありません.... 誰か私がこれを翻訳するのを手伝ってくれませんか....
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;
}
}
}
助けてくれてありがとう!