Creating a process
A process is normally created by sending the fork or forkAt: message to a block as shown in the following example. This process is immediately scheduled for execution. The fork message schedules the new process at the same priority as the process running the fork, while forkAt: allows the priority to be explicitly specified. When the new process runs, it evaluates the block. A reference to the new process can be retained by assigning it to an instance or temporary variable.
| process |
process := [Transcript show: 'The rain in Spain'; cr] fork.
A process can be created in a suspended state by sending the newProcess message to a block as shown in the next example. The new process is not scheduled for execution until it is sent the resume message.
| process |
process := [Transcript show: 'The rain in Spain'; cr] newProcess.
process resume.
Protocol also exists for creating a process and passing its creation block a set of arguments as shown in the following example. Here a string value is passed to a one-argument block. The number of arguments passed to the block must match the number of formal block parameters.
| process |
process := [:value | Transcript show: value; cr]
newProcessWith: #('The rain in Spain').
process resume.
Last modified date: 01/29/2015