Enclosed task activation must complete before main program begins

Hi, I completed the following assignment:

Write a program that is correct only because of the rule for task activation that the main program does not begin executing until the enclosed tasks have been activated

using either a nested package’s elaboration code, or functions with side effects changing shared (protected) variable. But though I have fun torturing the language, there is likely a better, more canonical use of that rule I can not think of, because I’m twisted. Could you enlighten me ?

You could use this in construction of a compiler:

  1. have the main-task be the code-generator;
  2. have dependent tasks be the IR-producer;
  3. have those depend on the parsing;
  4. have those depend on the lexing;
  5. have those depend on (or created from) the file at elaboration.

With a language like Ada, you could have multi-threaded lexing: one task for every line of the input-file. (This because there are no multi-line comments or strings.)

procedure P is
  task T is ...
begin
  ...