Previous: Memory Management Up: Synchronization Next: Examples
Pitfalls
Keeping the following points in mind when using single-assignment
variables will help to avoid many common mistakes.
- Single-assignment variables can be read by other threads
of control immediately after their definition has terminated.
For example, a structure that contains some single-assignment
fields and some mutable fields must usually be initialized such
that the mutable fields are defined before the single-assignment
fields. For an example of the subtlety of this pitfall, see
the second example in Section
of this
chapter.
In addition, the present implementation of the compiler places
the following restrictions on the single-assignment construct:
- A user-defined class cannot be declared to be single-assignment.
The sync construct can only be applied to fundamental types (that
could, in turn, be part of a user-defined class).