| | 88 | The use of iterators in for/forall loops can be implemented using a manager-worker strategy. When an iterator is encountered, the caller ("manager") spawns a new process to run the iterator. In addition to any declared parameters, the iterator has an extra parameter for the process ID of the manager. Whenever the iterator encounters a yield statement, it sends the yielded value to the manager. The manager then non-deterministically distributes the yielded value to one of n worker threads, which sets the loop variable to that value and runs the loop. When the end of the iterator is reached, it sends a special termination message. The manager then sends termination messages to all works and waits for them to complete. |