[fpc-devel] Linux thread priority mess (and possible implementation)
Hans-Peter Diettrich
DrDiettrich1 at aol.com
Thu Jun 24 13:44:41 CEST 2010
Graeme Geldenhuys schrieb:
> Looking at the rtl/unix/cthread.pp unit, I noticed two $Warning lines sayin
> that setting or getting thread priority is not implemented for any unix
> system. WHAT???
>
> I then thought I would go ahead and do the implementation. Seeing that
> cthreads using libc and POSIX implementation, there was lots of docs about
> it on the net, but the deeper I went the more confused I got.
>
> In summary, this info is what I gathered so far:
>
> * Linux thread priority is VERY confusing (compared to Windows).
> * You have Static and Dynamic thread priority.
> * You also have various Thread Scheduling priorities (different from
> thread priorities).
[...]
There exists a broad range of scheduler algorithms and implementations,
that can vary even with customized kernels of the same version, or with
a user specific configuration. Some schedulers maintain a dynamic
priority for every process or thread, that varies over time, so that
long-running high priority jobs do not block the entire system. True
realtime systems impose further constraints on (high priority) threads,
e.g. that they must either finish in a given time period, or must reduce
their own priority after the really time critical parts have been done,
or otherwise the system will assign them a lower priority automatically.
Thus priorities should only be considered as *hints* to the scheduler,
with unpredictable consequences on arbitrary machines. When an
application is tuned for best performance on a specific machine, it may
behave miserably on a similar machine with only a different scheduler,
or on a very different platform.
DoDi
More information about the fpc-devel
mailing list