[BUG] Processus priority with execv or pthread_create

Hi !

Some unexpected behavior where observed with the priority management Processus/Threads.

When you change the priority of a processus, you need to select a pcb, go to the main thread and change the priority inside of the main thread.

The thing is if you change the priority of the main thread and then you call execv, which will replace the main_thread of the processus by a new one. The new main_thread will not inherit the priority value and will use the default priority value. Is this behavior expected/intended ?

Another observed behavior, the new threads created for an application in userspace won’t inherit the priority of the main_thread of the processus but use the default one (see so3/kernel/thread.c). In my opinion this should be a bug.

To complete this, I tried to change the do_execv implementation to assign the current priority to the new thread and it works fine.
We should look into the standard to determine what is the standard behavior and fix SO3 accordingly. For this, I propose to expose the priority as an argument for the user_thread function or directly use the create_thread. It should also be noted that pthread uses the same underlying functions so it also has the “bug”.

Found this link(1) and this link (2) that new created threads inherits from priority assigned to the creating thread by default, and nice/renice should affect all threads belonging to the process. I guess we will implement this behaviour in SO3.

(1) " The default setting of the inherit scheduler attribute in a newly initialized thread attributes object is PTHREAD_INHERIT_SCHED ."
(2) “The nice value set with setpriority () shall be applied to the process. If the process is multi-threaded, the nice value shall affect all system scope threads in the process.”

1 Like