Programmer Reference : Common Process Model : Setting and modifying process priorities
Setting and modifying process priorities
ProcessorScheduler implements a round-robin with priorities scheduler. In other words, a running process will hold the CPU until one of the following occurs:
It performs an operation that causes it to suspend (see Table 7 for a list of the primary operations that cause a process to suspend).
Another process of higher priority is resumed.
The process is ended.
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:
1. systemBackgroundPriority
The priority of a system background process
2. userBackgroundPriority
The priority of a user background process
3. userSchedulingPriority
The priority of the user interface process (also the default priority of any process forked by the user interface process)
4. userInterruptPriority
The priority of any process forked by the user interface that should be run immediately
5. lowIOPriority
The usual priority for input/output processes
6. highIOPriority
The priority of the process monitoring the local network devices
7. timingPriority
The priority of the process monitoring the real-time clock
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
 
Last modified date: 05/12/2020