Previous: Unstructured Parallelism: spawn Up: Unstructured Parallelism: spawn Next: Argument Copying

Introduction

A final construct for creating parallel threads of execution is spawn. Parallel blocks and parfor statements have the nice property that a block terminates only when all their components terminate. They are the parallel equivalent of structured control flow statements in C and C++. The spawn statement is used to create a completely independent thread of control that executes in a concurrent (or possibly a fairly interleaved) manner with the thread that executes the spawn. Unlike the structured parallel statements, no parent-child relationship exists between the spawned thread and the spawning thread. There is no barrier or any form of implicit synchronization between the two, either at their beginning or at their termination.

Only functions can be spawned. A spawned function cannot return a value. Thus, spawn is similar in functionality to the thread creation facilities provided in many thread libraries.

The syntax for this statement is:


spawn f();

This unstructured parallelism is analogous to unstructured sequential code, with jumps and breaks in execution. Structured concurrency can be built on top of spawn, but this requires care and effort on the part of the programmer. The spawn statement should be used with care.

paolo@cs.caltech.edu