回复:比特币自动调整 nice 值
原始发布页
打开来源页面查看 1 个交叉存档
它为每个线程设置不同的优先级。生成线程以 PRIO_MIN 运行。其他线程很少占用 CPU,并以正常优先级运行。
#define THREAD_PRIORITY_LOWEST PRIO_MIN #define THREAD_PRIORITY_BELOW_NORMAL 2 #define THREAD_PRIORITY_NORMAL 0
从 Windows 优先级转换而来的这些优先级,很可能出自类似下面这样的表:
“下表展示了 nice 值与 Win32 优先级之间的对应关系。有关 Win32 优先级问题的更多信息,请参阅 Win32 文档中的 SetThreadPriority()。
nice 值 Win32 优先级 -20 至 -16 THREAD_PRIORITY_HIGHEST -15 至 -6 THREAD_PRIORITY_ABOVE_NORMAL -5 至 +4 THREAD_PRIORITY_NORMAL +5 至 +14 THREAD_PRIORITY_BELOW_NORMAL +15 至 +19 THREAD_PRIORITY_LOWEST”
如果你有更好的数值,欢迎提出建议。
另外,网上有些建议说 Linux 上应使用 PRIO_PROCESS,因为线程就是进程。如果这不是真的,也许就能解释为什么会意外设置整个应用程序的优先级。
// threads are processes on linux, so PRIO_PROCESS affects just the one thread setpriority(PRIO_PROCESS, getpid(), nPriority);
英文原文
展开英文原文
It sets different priorities for each thread. The generate threads run at PRIO_MIN. The other threads rarely take any CPU and run at normal.
#define THREAD_PRIORITY_LOWEST PRIO_MIN #define THREAD_PRIORITY_BELOW_NORMAL 2 #define THREAD_PRIORITY_NORMAL 0
The priorities converted from Windows priorities were probably from a table like this:
"The following table shows the mapping between nice values and Win32 priorities. Refer to the Win32 documentation for SetThreadPriority() for more information on Win32 priority issues.
nice value Win32 Priority -20 to -16 THREAD_PRIORITY_HIGHEST -15 to -6 THREAD_PRIORITY_ABOVE_NORMAL -5 to +4 THREAD_PRIORITY_NORMAL +5 to +14 THREAD_PRIORITY_BELOW_NORMAL +15 to +19 THREAD_PRIORITY_LOWEST"
If you have better values, suggestions welcome.
Also, there was some advice on the web that PRIO_PROCESS is used on Linux because threads are processes. If that's not true, maybe it accounts for unexpectedly setting the priority of the whole app.
// threads are processes on linux, so PRIO_PROCESS affects just the one thread setpriority(PRIO_PROCESS, getpid(), nPriority);