Previous: Data Dependencies and Flow of Control Up: Synchronization Next: Type Conversions

Single-Assignment Arguments and Return Values

Single-assignment variables can be used as function arguments (again, in exactly the same way that constant variables can be used). The pass-by-value semantics of function invocation in C and C++ guarantees that the single-assignment variable can be copied (and hence has been defined) before the function begins execution. For example:


void f(sync int i)  //Suspends here until i is defined
{  
  // At this point, we can assert that i has been defined
  ...
}

Similarly, a function can return a single-assignment type. This is not generally a useful thing, however, since an individual statement is evaluated sequentially in CC++. For example, to evaluate the expression a()+b(), first the function a() is executed, then the function b() is executed, then their result is summed. No potential parallelism between these two functions is exploited, so no synchronization in the form of single-assignment variables is required. Because functions that are spawned must be void functions, a single-assignment return type is not useful in that case either. Thus, it is always possible to replace a function that returns a single-assignment type with one that returns a mutable type, without altering the semantic meaning of the program.

paolo@cs.caltech.edu