ProcessorScheduler implements a round-robin with priorities scheduler. In other words, a running process will hold the CPU until one of the following occurs:
At that point, the scheduling algorithm ensures that the highest priority process that is ready to run next. If there is more than one process satisfying this criterion, then the process that has been waiting longest is selected for execution.
Consequently, the order in which processes run can be influenced by changing the priority assigned to a process. There are seven preassigned priority levels. The priority constants in increasing order are as follows:
On many platforms the priorities are actually mapped to the integers 1 through 7; however, it is poor programming style to reference the priorities directly as integral values. The preferred approach is to use the priority accessors provided by ProcessorScheduler. You can query a process priority and modify its value as required. In the next example, the priority and priority: messages are used to query and modify the priority of the process. Note, however, that if a priority is changed, the change has no effect on scheduling until the next process switch.
| process | process := [Transcript show: 'The rain in Spain'; cr] newProcess. Transcript show: process priority printString; cr. process priority: Processor userBackgroundPriority. Transcript show: process priority printString; cr.
Table 7. Primary operations that cause a process to suspend
Operation | Relevant method | Method's class |
---|---|---|
Directly suspend a process | suspend | Process |
Wait on a semaphore | wait | Semaphore |
Wait on a delay | wait | Delay |
Open a debugger on an active process | reportError:resumable:startBP | EtWindowSystemStartUp |
Debug an active process from within a debugger | addProcess | EtDebugger |
Use execLongOperation to evaluate a block in the background (causes the regular UI process to suspend) | execLongOperation: | EtWindow |
Resume another process of higher priority | resume | Process |
Create another process of higher priority (when the next context switch occurs) | forkAt: | Block |
Change the priority of another process to be greater than this process (when the next context switch occurrs) | priority: | Process |