# Re: bitcoin auto-renice-ing

Post by: satoshi on March 15, 2010, 06:44:12 PM

It sets different priorities for each thread. &nbsp;The generate threads run at PRIO_MIN. &nbsp;The other threads rarely take any CPU and run at normal.

\#define THREAD_PRIORITY_LOWEST &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PRIO_MIN<br>
\#define THREAD_PRIORITY_BELOW_NORMAL &nbsp;&nbsp;&nbsp;2<br>
\#define THREAD_PRIORITY_NORMAL &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0

The priorities converted from Windows priorities were probably from a table like this:

&nbsp;&nbsp;&nbsp;"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 &nbsp;&nbsp;&nbsp;Win32 Priority<br>
-20 to -16 &nbsp;&nbsp;&nbsp;THREAD_PRIORITY_HIGHEST<br>
-15 to -6 &nbsp;&nbsp;&nbsp;THREAD_PRIORITY_ABOVE_NORMAL<br>
-5 to +4 &nbsp;&nbsp;&nbsp;THREAD_PRIORITY_NORMAL<br>
+5 to +14 &nbsp;&nbsp;&nbsp;THREAD_PRIORITY_BELOW_NORMAL<br>
+15 to +19 &nbsp;&nbsp;&nbsp;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. &nbsp;If that's not true, maybe it accounts for unexpectedly setting the priority of the whole app.

&nbsp;&nbsp;&nbsp;&nbsp;// threads are processes on linux, so PRIO_PROCESS affects just the one thread<br>
&nbsp;&nbsp;&nbsp;&nbsp;setpriority(PRIO_PROCESS, getpid(), nPriority);

---

Source file: bitcoin-forum-satoshi-nakamoto.tgz

External link: https://bitcointalk.org/index.php?topic=72.msg717#msg717
