真的不明白为什么我的程序不工作

发布于 2024-10-11 06:46:50 字数 1366 浏览 0 评论 0原文

我确实花了很多时间来解决这个问题并四处寻找解决方案,但我似乎找不到问题所在。

我正在学习如何编写 occam 代码并编写以下程序:

PROC light (CHAN OF BYTE screen, CHAN OF INT light.change)
  INT light.on :
  WHILE TRUE
    SEQ
      light.change ? light.on
      IF
        light.on = 1
          screen ! 'y'
        TRUE
          SKIP
:

PROC test(CHAN OF BYTE keyboard, scr)
  CHAN OF INT to.light :
  INITIAL INT on IS 1(INT) :
  BYTE b :
  SEQ
    light(scr, to.light)
    WHILE TRUE
      SEQ
        keyboard ? b
        IF
          b = 'o'
            to.light ! on
          TRUE
            SKIP
:

我想做的就是当我按“o”键时从一个进程与另一个进程进行通信。

我从 (KRoC) 编译器收到的错误消息是:

Error at lift.occ:11
Program failed, state = e, eflags = 00000000

这是 light.on = 1 行。

据我所知, light PROC 将等待其 light.change channel 然后将其分配给其 light.on 变量。然后,程序将继续执行条件语句 IF,其中 light.on = 1 行在本例中应计算为 <代码>true。但我却收到了这个错误。

我尝试使用 -verbose 标志,但编译器表示您不能将其用于 .occ 文件。

有谁知道我如何或是否可以从编译器获取更详细的信息?

对此的任何帮助将不胜感激。

谢谢

I've really spent a lot of time working at this problem and googling around to find a solution, but I can't seem to find what's wrong.

I've learning how to code occam and have the following program:

PROC light (CHAN OF BYTE screen, CHAN OF INT light.change)
  INT light.on :
  WHILE TRUE
    SEQ
      light.change ? light.on
      IF
        light.on = 1
          screen ! 'y'
        TRUE
          SKIP
:

PROC test(CHAN OF BYTE keyboard, scr)
  CHAN OF INT to.light :
  INITIAL INT on IS 1(INT) :
  BYTE b :
  SEQ
    light(scr, to.light)
    WHILE TRUE
      SEQ
        keyboard ? b
        IF
          b = 'o'
            to.light ! on
          TRUE
            SKIP
:

All I'm trying to do is communicate from one process to another when I press the 'o' key.

The error message I'm getting from the (KRoC) compiler is:

Error at lift.occ:11
Program failed, state = e, eflags = 00000000

which is the light.on = 1 line.

As far as I can see, the light PROC will wait for some input on its light.change channel and will then assign it to its light.on variable. The program will then proceed to a conditional statement IF, where the light.on = 1 line should in this case evaluate to true. But instead I get this error.

I have tried using the -verbose flag, but the compiler says that you can't use it for .occ files.

Does anyone know how or if I can get more detailed info from the compiler?

Any help on this would be greatly appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩余の解释 2024-10-18 06:46:50

上面的代码为我编译,当运行达到死锁时,

james:conc$ occbuild --program light.occ 
james:conc$ light
KRoC: deadlock: no valid processes found in workspace(s)

KRoC: program deadlocked (no processes to run)

我还可以让它以详细模式运行,如下所示

occbuild -v --program light.occ 

在不同的说明上,您可能想要更改结构。尝试使用三个 PROC

PROC is.light.on(CHAN BYTE screen! , CHAN INT light.control)
  WHILE TRUE
...output to terminal if light is on or off

PROC light.switch(CHAN BYTE keyboard? , CHAN INT light.control)
  WHILE TRUE
...use the keyboard to turn light on and off

PROC light(CHAN BYTE keyboard? , screen!)
  CHAN INT light.control:--0 for light on;1 for light off
  PAR
    light.switch(keyboard? , light.control!)
    is.light.on(screen! , light.control?)

The above code compiles for me and when run reaches deadlock

james:conc$ occbuild --program light.occ 
james:conc$ light
KRoC: deadlock: no valid processes found in workspace(s)

KRoC: program deadlocked (no processes to run)

I can also get it to run in verbose mode as below

occbuild -v --program light.occ 

On a different note you might want to change your structure. Try having three PROC's

PROC is.light.on(CHAN BYTE screen! , CHAN INT light.control)
  WHILE TRUE
...output to terminal if light is on or off

PROC light.switch(CHAN BYTE keyboard? , CHAN INT light.control)
  WHILE TRUE
...use the keyboard to turn light on and off

PROC light(CHAN BYTE keyboard? , screen!)
  CHAN INT light.control:--0 for light on;1 for light off
  PAR
    light.switch(keyboard? , light.control!)
    is.light.on(screen! , light.control?)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文