Hi,
I’ve been wondering, are select statements allowed outside task bodies ?
Answer: Yes. For some reason I remembered falsely that they weren’t, because of a past attempt, but I probably misremembered and confused the accept alternative for the non-task-centric features, ATCs and timed/condtional entry calls.
Because the “environment task” is the task that the OS provides and attaches/assigns the program to. There is no way to signal the rendezvous that ought to be used (because the OS has no idea of the accept that this would have) because it is a completely generalized method… — You can use delay, IIRC.
Hm, have you tried throwing timer-stuff in your main program?
The “main program” though, IIRC, is not the environment task: [again IIRC], the environment task is the conceptual “master task” which spawns your program’s “main program”.
(I think I’m mis-remembering terminology.) Conceptually:
-- Conceptual/virtual package/thread-of-control;
-- ie the 'context'.
Package Environment is
-- Environment-variables and interfaces here.
End Environment;
------------
With Main_Program;
Package body Environment is
-- Conceptual Master for the program's task.
Begin
Main_Program;
End Environment;
-----------
-- This is the only actual code:
With Ada.Text_IO;
Procedure Main_Program is
Begin
Ada.Text_IO.Put_Line( "Hello World." );
End Main_Program;
The environment task does elaboration, then call the main-program procedure. Upon return from that, it awaits termination of library-level tasks, then finalizes library-level controlled objects.
Selective accept statements can only appear in task bodies, since that’s the only place that accept statements can appear.
Timed and conditional entry calls and asynchronous transfer of control can appear anywhere.
Ah thanks, it wasn’t clear to me either way while reading the RM
I don’t know why I made the confusion. Probably an attempt when it wasn’t too clear to me, and I misremembered.