Parallel tasks

In reply to ben@SystemVerilog.us:

The example from the LRM you show is about the sentence before the two sentences you quoted, and last sentence. It is not trying to explain the restriction in the first sentence.

The issue with arguments passed by reference is dealing with the end of life of a variable with an automatic lifetime. The life of an automatic variable begins when entering the procedural block (begin/fork, task/function) containing its declaration. Normally its life ends when exiting that block, but gets extended by any fork block enclosed within its scope. Calling a task or function procedure does not make that procedure an enclosing scope.

An contrived illegal example would be:

module top;
  task automatic t1;
    int i1=4;
    t2(i1);
    #1 return; // i1's lifetime ends when this task returns at time  1
  endtask
  task t2(ref int arg); 
    fork
      while(arg>0) #1 $display($time, arg--);
    join_none
  endtask
  initial fork t1; t1; join
endmodule

The problem with this code when calling t2, the lifetime of arg needs to exist for the duration of the while loop., but it disappears when t2 exits.