Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-02

values for ThreadSetPriority

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Seth Grover

After reading the online docs, and searching this list, I'm still confused. Hopefully someone can straighten me out.

http://www.hu.freepascal.org/docs-html/rtl/system/threadsetpriority.html says that it takes for a priority values from -15 to 15. The comment to the right of the declaration says that "0" is normal. Are these numbers like nice's, where negative numbers are more favorable (higher priority) and positive numbers are less favorable (lower priority)?

Also, to further confuse my mind, I found this:
http://community.freepascal.org:10000/docs-html/rtl/classes/tthreadpriority.html which has some enumerations. How do those come into play? Are those just for TThread descendents?

I'm just trying to find the correct cross-platform approach for changing thread priority of threads started with BeginThread.

Thanks,

-SG

This email is fiction. Any resemblance to actual events or persons living or dead is purely coincidental. Seth Grover sethdgrover[at]gmail[dot]com

Reply by email

Graeme Geldenhuys
to Seth Grover
Seth Grover wrote
http://www.hu.freepascal.org/docs-html/rtl/system/threadsetpriority.html says that it takes for a priority values from -15 to 15. The comment

I always thought I knew the answer, but then when I searched for the answers in the source code, it started getting really confusing! :-(

In classesh.inc we have:

  TThreadPriority = (tpIdle, tpLowest, tpLower, tpNormal, tpHigher, tpHighest,
    tpTimeCritical);

Then in unix/thread.inc we have:

  // stupid, considering its not even implemented...
  Priorities: array [TThreadPriority] of Integer =
   (-20,-19,-10,0,9,18,19);

This already conflicts with the documentation which says the range is -15 to 15. Go figure!

Then we also have in linux/pthread.inc

  const
     THREAD_PRIORITY_IDLE               = 1;
     THREAD_PRIORITY_LOWEST             = 15;
     THREAD_PRIORITY_BELOW_NORMAL       = 30;
     THREAD_PRIORITY_NORMAL             = 50;
     THREAD_PRIORITY_ABOVE_NORMAL       = 70;
     THREAD_PRIORITY_HIGHEST            = 80;
     THREAD_PRIORITY_TIME_CRITICAL      = 99;

So there you go! I'm not just as confused as you are. ;-)

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Jonas Maebe
to Seth Grover: After reading the online docs, and searching this list, I'm still confused. Hopefully…
Seth Grover wrote 5 lines
http://www.hu.freepascal.org/docs-html/rtl/system/threadsetpriority.html says that it takes for a priority values from -15 to 15. The comment to the right of the declaration says that "0" is normal. Are these numbers like nice's, where negative numbers are more favorable (higher priority) and positive numbers are less favorable (lower priority)?

This function is currently only hooked up for Windows and is mapped directly to the "WinThreadSetPriority" win32 api function (which directly takes these inputs). Whatever MSDN defines as the meaning of that parameter is what it will also mean on other platforms, when/if it's hooked up there.

Also, to further confuse my mind, I found this: http://community.freepascal.org:10000/docs-html/rtl/classes/tthreadpriority.html which has some enumerations. How do those come into play? Are those just for TThread descendents?

Yes.

I'm just trying to find the correct cross-platform approach for changing thread priority of threads started with BeginThread.

In theory the function to use would be system.threadsetpriority, but in practice this will only work on Windows currently.

Jonas

Reply by email