Hi,

After some tests, it seems new tasks will inherit the parent
priority.

However for threads, given

On Sat, Apr 11, 2026 at 09:02:53PM +0100, Diego Nieto Cid wrote:
>     kern/thread.c:338:      thread_template.max_priority = BASEPRI_USER;
>     kern/thread.c:422:      *new_thread = thread_template;

and the following code in thread_create (kern/thread.c):

    501  new_thread->priority = parent_task->priority;

            This inherits the task priority which after
            setpriority(PRIO_PROCESS, 0, -20) is set to 5.

    502  if (pset->max_priority > new_thread->max_priority)
    503    new_thread->max_priority = pset->max_priority;

            The if above takes care of the max_priority of
            the thread. The call to setpriority would change
            the pset max priority to 5, but as it is not bigger
            than BASEPRI_USER its body is not executed.

    504  if (new_thread->max_priority > new_thread->priority)
    505    new_thread->priority = new_thread->max_priority;

            Finally, the thread priority is taken care of by
            these two lines. As max_priority is bigger than 5,
            the initial value set by parent_task->priority, it
            is reset to that bigger value which happens to be
            BASEPRI_USER (which comes from template_thread,
            line 422, shown above in my previous email).


For short, as a result of this series of ifs, a thread is
always born with priority set to max_priority set to BASEPRI_USER.
No matter what the task priority or the processor set max_priority
is set to.

Does the setpriority call make any sense if the new threads do not
honor the very setting it is meant to change?

Taking max_priority out from the thread template could be a solution
but it looks quite a pervasive change.

Thanks,
Diego

Reply via email to