1

I have a task that has only one Stop entry, and an else section, how can i implement that the task do the thing in the else section in an infinite loop but when Stop is called it is set ready to terminate

here is the select part

select  
  accept Stop do  
    exit;  
  end Stop;  
else  
  delay 3.0;  
  --do something
end select;
BenJoe
  • 15
  • 3

1 Answers1

1

Do this (added assumed loop statement for clarity):

loop
   select
      accept Stop;
      exit;
   or
      delay 3.0;
      --  do something
   end select;
end loop;

Mind that the body of an accept statement is only necessary if you need to process its parameters. Since Stop has none, it makes no sense for that accept statement to have a body.

Your error comes from this rule from the LRM, 5.7:

An exit_statement that applies to a given loop_statement shall not appear within a body or accept_statement, if this construct is itself enclosed by the given loop_statement.

I also changed your else to an or so that the Stop is accepted during the whole waiting time, which I assume is what you want. With else, the Stop is only accepted at the time the select is being executed, not after the delay has started.

flyx
  • 35,506
  • 7
  • 89
  • 126