首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java等待语句-并发编程

Java等待语句-并发编程
EN

Stack Overflow用户
提问于 2013-03-06 04:29:02
回答 1查看 1.2K关注 0票数 0

我有一个问题是我们的讲师给出的。它指的是等待上环形交叉路口的汽车,这样环形交叉路口就不会堵塞。据推测,他给了我们一个使用"await( B,S)“语句来解决这个问题的方法,并要求我们将其转换为使用信号量,但是他给出的代码并不计算lol。我不知道他在玩什么,但这在Java中是没有意义的……有没有人能帮我翻译一下...

代码语言:javascript
复制
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;
}
}
}

提前感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2013-03-07 05:10:04

他最终告诉我们的是,他给我们的问题是多年前的事了。问题中的代码是冗余Java。对于任何其他有一个愚蠢的老师的人来说,当这种格式的代码出现"await((numberOnRoundabout<=6),numberOnRoundabout++)“时,它就是旧的Java。翻译过来,它将是一系列使用其中设置的条件创建的线程对象。

e.g

代码语言:javascript
复制
public synchronized void myStop() {
      this.runningFlag=false;
      t.interrupt();
      } // end myStart

我真的希望没有人需要这些信息!永远不会!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15233444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档