Bug 57014 - Starvation in cyg_libc_stdio_flush_all_but()?
Starvation in cyg_libc_stdio_flush_all_but()?
Product: eCos
Classification: Retired
Component: C library (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jonathan Larmour
Jonathan Larmour
Depends On:
  Show dependency treegraph
Reported: 2001-12-03 04:44 EST by Andrew Lunn
Modified: 2007-04-18 12:38 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-12-05 04:53:08 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Simple test case (1.02 KB, text/plain)
2001-12-03 08:36 EST, Need Real Name
no flags Details
Here is the patch (2.38 KB, patch)
2001-12-04 18:32 EST, Jonathan Larmour
no flags Details | Diff

  None (edit)
Description Andrew Lunn 2001-12-03 04:44:12 EST
Description of Problem:

Under some circumstances, my application's UI freezes but background threads
still run. The following scenario causes it to happen:

  1. Two threads; one, called CLI, handles the command line interface. The
     second, say WRK, does some work and prints messages to the console.

  2. priority(CLI) > priority(WRK)    (higher priority, not higher value)

  3. While WRK is printing a message to stdout, the user hits RETURN which
     causes the CLI thread to wake up and display a prompt to stderr. This ends
     in cyg_libc_stdio_flush_all_but() with the CLI thread looping endlessly
     trying to flush stdout since WRK owns stdout stream's lock and cannot
     release it because of its lower priority.

Version-Release number of selected component (if applicable): 1.5.2
Comment 1 Jonathan Larmour 2001-12-03 07:48:20 EST
[ Ideally I'll need a testcase.... ]

I suspect what is required is to replace the mutex "trylock" with a lock when
going through the loop a second time. This allows mutex priority inheritance to
work properly.

I'll look at it closer. Is this a contractual bug report or a contrib one? I
suspect the former so I'll treat it as such :-).

Comment 2 Andrew Lunn 2001-12-03 08:03:47 EST
I submitted this with my Ascom Contract hat on.
Comment 3 Need Real Name 2001-12-03 08:36:46 EST
Created attachment 39408 [details]
Simple test case
Comment 4 Jonathan Larmour 2001-12-04 18:31:52 EST
It took me a little longer than expected (I got bogged down trying to get debug
hardware to work right), but this should hopefully solve it. I've tried it with
your test case (with the cyg_thread_delay in worker() removed, to give it proper
effect) and it appears happy.

Can you confirm?
Comment 5 Jonathan Larmour 2001-12-04 18:32:43 EST
Created attachment 39647 [details]
Here is the patch
Comment 6 Need Real Name 2001-12-05 03:24:51 EST
Yes, the patch solves the problem. Thanks.
Comment 7 Andrew Lunn 2001-12-05 04:53:03 EST
Great. I checked the patch into our CVS server at Solothurn.

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