Previous: Introduction Up: Unstructured Parallelism: spawn Next: Unstructured Termination

Argument Copying

Spawn guarantees that the arguments to the function being spawned are copied before the spawning thread continues to the next instruction. Thus, the following code has the expected effect:


for (i=0; i<N; i++)  
  spawn f(i);

The argument to f() is copied before the next instruction executes (which will increment i). Thus, at the end of this sequential for loop, there are possibly concurrent threads of control: the original thread and the N threads spawned in the loop. Each of the N instances of the function f() has a distinct value for its integer argument. We can say nothing, however, about when each of the instances of f() will begin or terminate execution, either with respect to each other or with respect to the spawning thread.

For consistency with the C and C++ language definitions, the order of argument evaluation for the spawned function is not defined, but all side-effects are guaranteed to occur before the spawned function begins execution. Consider the following example:


spawn f(i++, &i)

We do not know when f() will begin execution, but when it does it will have a pointer to the incremented value of i (unless of course the value of i has been modified; see Section ).

paolo@cs.caltech.edu