This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
The problem with __pthread_manager_adjust_prio
- From: "H . J . Lu" <hjl at lucon dot org>
- To: GNU C Library <libc-alpha at sources dot redhat dot com>
- Date: Wed, 20 Mar 2002 16:50:08 -0800
- Subject: The problem with __pthread_manager_adjust_prio
There is a race condition between __pthread_manager_adjust_prio
called from pthread_setschedparam and pthread_start_thread on
manager_thread->p_priority. When a thread is calling
pthread_setschedparam, the new thread may inherit SCHED_FIFO from
the manager thread. That is
Thread A calls pthread_setschedparam
calls __pthread_manager_adjust_prio
calls __sched_setscheduler (SCHED_FIFO) on the manager thread.
The main thread calls pthread_create
The manager threads calls pthread_start_thread. It does
if (manager_thread->p_priority > 0)
__sched_setscheduler (SCHED_OTHER)
Since manager_thread->p_priority may not be changed by
__pthread_manager_adjust_prio yet, the new thread may inherit
SCHED_FIFO. Here is a patch. the worst case is pthread_start_thread
may call __sched_setscheduler (SCHED_OTHER) before
__sched_setscheduler (SCHED_FIFO) is called on the manager thread.
H.J.
----
2002-03-20 H.J. Lu <hjl@gnu.org>
* manager.c (__pthread_manager_adjust_prio): Set
manager_thread->p_priority before calling __sched_setscheduler.
--- linuxthreads/manager.c.sched Tue Mar 12 10:24:37 2002
+++ linuxthreads/manager.c Wed Mar 20 16:47:54 2002
@@ -1082,6 +1082,6 @@ void __pthread_manager_adjust_prio(int t
param.sched_priority =
thread_prio < __sched_get_priority_max(SCHED_FIFO)
? thread_prio + 1 : thread_prio;
- __sched_setscheduler(manager_thread->p_pid, SCHED_FIFO, ¶m);
manager_thread->p_priority = thread_prio;
+ __sched_setscheduler(manager_thread->p_pid, SCHED_FIFO, ¶m);
}