Bug 61539 - The race condition in linuxthreads
Summary: The race condition in linuxthreads
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc   
(Show other bugs)
Version: 7.3
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
Blocks: 61901 67218 79579
TreeView+ depends on / blocked
Reported: 2002-03-21 07:28 UTC by hjl
Modified: 2016-11-24 15:00 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2003-04-23 22:40:31 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
A simple patch (629 bytes, patch)
2002-03-21 07:29 UTC, hjl
no flags Details | Diff
A patch with spinlock (2.45 KB, patch)
2002-03-21 08:16 UTC, hjl
no flags Details | Diff

Description hjl 2002-03-21 07:28:06 UTC
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.

Comment 1 hjl 2002-03-21 07:29:50 UTC
Created attachment 49328 [details]
A simple patch

Comment 2 hjl 2002-03-21 07:32:02 UTC
I don't know if a spinlock for manager_thread->p_priority
is a better fix. Also we need to check if there are any other
race conditions like that for other manager_thread fields.

Comment 3 hjl 2002-03-21 08:16:31 UTC
Created attachment 49329 [details]
A patch with spinlock

Comment 4 hjl 2002-03-21 08:17:22 UTC
I uploaded another patch with spinlock.

Comment 5 Ulrich Drepper 2003-04-23 22:40:31 UTC
I've explained a few times on the libc lists that the patches aren't adequate. 
And probably no userlevel solution can be adequate.  But this is all pointless
now.  LinuxThreads stays as it is, correct or not.  I'm closing the bug therefore.

Note You need to log in before you can comment on or make changes to this bug.