| | 244 | === Spawning a new process: `$spawn` |
| | 245 | |
| | 246 | A spawn expression is an expression with side-effects. It spawns a new process and returns a reference to the new process, i.e., an object of type $proc. The syntax is the same as a procedure invocation with the keyword `$spawn` inserted in front: |
| | 247 | {{{ |
| | 248 | $spawn f(expr1, ..., exprn) |
| | 249 | }}} |
| | 250 | Typically the returned value is assigned to a variable, e.g., |
| | 251 | {{{ |
| | 252 | $proc p = $spawn f(i); |
| | 253 | }}} |
| | 254 | If the function `f` returns a value, that value is simply ignored. |
| | 255 | |
| 341 | | === `$parfor` |
| 342 | | |
| 343 | | === `$spawn` |
| 344 | | |
| 345 | | === `$when` |
| | 353 | === Parallel for loop: `$parfor` |
| | 354 | |
| | 355 | A parallel for loop statement has the form |
| | 356 | |
| | 357 | `$parfor` `(``int` ''i1''`,` ...`,` ''in'' `:` ''dom''`)` ''S'' |
| | 358 | |
| | 359 | The syntax is exactly the same as that for the sequential domain iteration loop `$for`, only with `$parfor` replacing `$for`. |
| | 360 | |
| | 361 | The semantics are as follows: when control reaches the loop, one process is spawned for each element of the domain. That process has local variables corresponding to the iteration variables, and those local variables are initialized with the components of the tuple for the element of the domain that process is assigned. Each process executes the statement ''S'' in this context. Finally, each of these processes is waited on at the end. In particular, there is an effective barrier at the end of the loop, and all the spawned processes disappear after this point. |
| | 362 | |
| | 363 | === Guarded commands: `$when` |