This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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, &param);
   manager_thread->p_priority = thread_prio;
+  __sched_setscheduler(manager_thread->p_pid, SCHED_FIFO, &param);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]