Unix to Windows Porting Dictionary for HPC |
|
|
RSS
LinksFunction List
|
Table of Contents The priority of a process determines how much CPU time it receives, when it will receive its allocated time and the order it will run in relation to other processes. The method of expressing and setting a processes priority is different between Unix and Windows. Unix process priority is traditionally called a "nice value". Nice values range from -20 (highest) to +20 (lowest) with the typical default nice value being 0 (zero). Most Windows users are used to a descriptive label such as "High" or "Normal" but the Windows priority is actually a numeric value. Numeric value range from 0 (lowest) to 31 (highest). Typically Windows processes are grouped into priority classes. Each priority class then has several priority levels that correspond to actual priority values. Extreme care must be taken if you decide to use the high priority or real-time priority classes because of the severe effects on the overall system operation that can happen. The Unix nice value of 0 (zero) mapps to the Windows priority value of 8 (Normal priority class, thread priority normal). Note that a higher numeric value with Windows denotes a higher priority while Unix denotes this as a lower priority. Further Windows priorities do not deal with negative values. It is recommended that when converting source code or making code more portable that macros be used instead. This can help clarify the code as being correct. Note: The Windows function SetThreadPriority() should is for thread priority rather than process priority.
#include <windows.h>
#include <math_u.h>
#ifdef defined(_MSC_VER) && !defined(__INTERIX)
# define SetOurPrio(x) SetPriorityClass(GetCurrentProcess(), (x))
# define MY_LOW_PRIORITY BELOW_NORMAL_PRIORITY_CLASS
# define MY_NORMAL_PRIORITY NORMAL_PRIORITY_CLASS
# define MY_HIGH_PRIORITY ABOVE_NORMAL_PRIORITY_CLASS
#else /* _MSC_VER && !__INTERIX */
# define SetOurPrio(x) setpriority(PRIO_PROCESS, 0, (x))
# define MY_LOW_PRIORITY 3
# define MY_NORMAL_PRIORITY 0
# define MY_HIGH_PRIORITY -2
#endif /* _MSC_VER && !__INTERIX */
if (SetOurPrio(MY_NORMAL_PRIORITY)) {
printf("error: could not set priority\n");
}
|
|
|
|