comp.lang.ada
 help / color / mirror / Atom feed
* Select + Accept syntax question
@ 2016-08-27 18:26 Andrew Shvets
  2016-08-27 19:20 ` Niklas Holsti
  2016-08-27 19:36 ` Jeffrey R. Carter
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew Shvets @ 2016-08-27 18:26 UTC (permalink / raw)


Hello,

When working with tasks, you can use a selective wait in order to have your task quickly check its queue of messages and see if there any waiting for it (i.e. a selective wait.)  Now, in order to further build on this, guards can be used to ensure that certain conditions are met before processing some messages.

After messing around with both concepts, I created the following example:
while Go_Loop LOOP
  select
    when Internal_Value = 0 =>
      accept Input(Value : in Integer) do
        Internal_Value := Value;
      end Input;
  or
    when Internal_Value /= 0 =>
      accept Retrieve(Value : out Integer) do
        Value := Internal_Value;
      end Retrieve;

The one thing that threw me for a loop was when I put any type of code right before the above two accept keywords, like so:
while Go_Loop LOOP
  select
    when Internal_Value = 0 =>
      Ada.Text_IO.Put_Line("hello world");
      accept Input(Value : in Integer) do
        Internal_Value := Value;
      end Input;
  or
    when Internal_Value /= 0 =>
      Ada.Text_IO.Put_Line("hello world");
      accept Retrieve(Value : out Integer) do
        Value := Internal_Value;
      end Retrieve;

And I get the following output from the compiler:

> gnatmake -g .\task_demo_11.adb
gcc -c -I.\ -g -I- .\task_demo_11.adb
task_demo_11.adb:25:16: missing "END SELECT;" for "SELECT" at line 18
task_demo_11.adb:25:17: select alternative ("ACCEPT", "ABORT", "DELAY") expected
task_demo_11.adb:38:07: "OR" not allowed here
task_demo_11.adb:42:07: no "SELECT" for this "END SELECT"
gnatmake: ".\task_demo_11.adb" compilation error

Why does this happen?  Why can't I have code right before the accept?  I can see a compilation error if there is no accept...


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-08-28  6:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-27 18:26 Select + Accept syntax question Andrew Shvets
2016-08-27 19:20 ` Niklas Holsti
2016-08-27 19:47   ` Andrew Shvets
2016-08-28  6:52     ` Niklas Holsti
2016-08-27 19:36 ` Jeffrey R. Carter
2016-08-27 19:48   ` Andrew Shvets
2016-08-27 23:22     ` Jeffrey R. Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox