Thread Priorities

In a multithreaded program, it is likely that many threads will be active at the same time. To ensure that each active thread gets its proper share of CPU time, the runtime tracks certain types of operations, such as DISPLAY, file IO and basic computation operations, and periodically switches the executing thread. Each of these opportunities to change threads is called a switch point. The execution priority of each thread helps to determine which thread gets control at each switch point.

A thread's execution priority is an integer value. By default, all threads start with a priority value of 100. You use a Format 12 SET statement to change a thread's priority value.

Threads receive control in proportion to their priority. The higher the priority, the more often that thread gets control at a switch point. Thus, a thread with a priority of 50 gains control half as often as a thread with a priority of 100. Of course, if a thread is paused for any reason, such as waiting for input, the thread does not gain control. The minimum priority for a thread is one (1), the maximum is 32767.

Three runtime configuration variables, SWITCH_PERIOD , DISPLAY_SWITCH_PERIOD , and IO_SWITCH_PERIOD , can be used to affect how the runtime manages thread switching.