Argument Passed by Reference cannot be used within fork-join_any/join_none

In reply to Jonathan_Alvarez:

Jonathan,

This is an LRM restriction (See section Section 9.3.2 "Parallel blocks in the 1800-2012 LRM). The reason behind this restriction has to do with the fact that the lifetime of any variable referenced inside a fork/join_none/join_any block has to exist throughout the life of the fork block. Recall that there are these kinds variable lifetimes

  • Static - permanent and not an issue for this problem
  • Automatic - exists for the duration of a block activation
  • Dynamic - class object memory management by active references.
  • Queues, dynamic arrays, and associative array add another dimension to the above for each element.

The problem is when you pass variable by reference, you have no information about what kind of storage class the variable belongs to in order to be able to extend it’s lifetime. You only have the reference to a generic variable type that matches the type of the reference.

Suppose you have a task with a ref argument to an int, and you call that task passing it class member that is an int. The code that calls that task only only passes a reference to that int, and not the handle to the class it belongs to. same problem with passing an element of an array.

If the compiler in-lines the task (replacing the call to the task with the contents of the source code of the task) you can get around this restriction. But then you can’t take advantage of separate compilation( compiling the task definition in a separate step from compiling the code that calls the tak).