Previous: Argument Copying Up: Unstructured Parallelism: spawn Next: Sharing Data
Because the termination of a spawned thread is not synchronized with the spawning thread, it is an error (compile-time checked) to spawn a function that returns a value. All spawned functions must be void functions.
Again, because there is no synchronization between spawned and spawning threads, care must be taken that main() does not terminate before any of the spawned threads. The following example illustrates the problem:
void f(int i) {...} int main() { spawn f(2); return 0; }
The end of a CC++ program is defined to occur (as with C and C++) at the termination of main(). Thus, the program in the above example could terminate before f() begins execution. Such behavior is almost certainly a programming error.
The lack of implicit synchronization with spawn transfers
responsibility for synchronization to the programmer. Barriers,
or any other form of synchronized behavior, must be explicitly
programmed. We will return to this question once we have
introduced the synchronization mechanism provided by CC++
(Chapter ).