Method Thread():setPriority() Foundation

Sets the priority of a thread.

:setPriority( <nPriority> ) --> lSuccess
Constants listed in the following table can be used for <nPriority>. They are defined in the file THREAD.CH
Constants for general purpose priorities of a thread
Constant Description
PRIORITY_HIGHEST Highest priority
PRIORITY_NORMAL Normal priority
PRIORITY_LOWEST Lowest priority
Constants for special purpose priorities of a thread
Constant Description
PRIORITY_TIME_CRITICAL Thread executes code as soon as it is Ready to Run
PRIORITY_IDLE Thread executes code when no other thread is Ready to Run or executing code

The method :setPriority() returns the value .T. (true) if the priority for the thread can be set, otherwise it returns .F. (false).


The method :setPriority() allows the priority of threads to be specified. The operating system distributes processor time to various threads according to their priority. Threads with high priority receive precedence when processor time is assigned and these threads are executed prior to threads having a lower priority.

By default, the threads in an Xbase++ program have the priority PRIORITY_NORMAL. An Xbase++ application is provided processor time along with other programs based on precedence. The priority does not normally need to be changed.

The Thread object allows thread priority to be changed and appropriate handling of this remains the responsibility of the programmer. Raising the priority of a thread only makes more processor time available to the thread from the operating system. It does not ensure that a program will run faster. In the worst case, if the priority is set too high, it would mean that multi-tasking and multi-threading are no longer possible since the Xbase++ application is allocated all of the processor time and other programs are not able to run until the Xbase++ application has terminated.


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.