Previous: Sharing Data Up: Unstructured Parallelism: spawn Next: Examples

Pitfalls

Some potential problems to keep in mind when using spawn:

  1. Spawned functions cannot return a value.

  2. Explicit synchronization points must be programmed when using spawned functions; otherwise there is no guarantee they will begin execution before the end of main() is encountered. How to construct such synchronization points is discussed in Chapter .

  3. Great care must be exercised when passing pointers (or C++ references) to spawned functions, as this often leads to dangerous sharing of mutable variables.

  4. To understand complicated spawning expressions, the precedence in the order of evaluation in a function call must be understood. The function call is spawned, not the evaluation of any prefix operators. For example:
    
    spawn f->g()->h(); 
    

    First the pointer f is evaluated, then the function g() is executed, and then the result is used to determine which function h() is spawned. The spawning occurs only at the highest level function call.

paolo@cs.caltech.edu