delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/01/26/05:24:32

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Wed, 26 Jan 2011 11:23:56 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: 1.7.7: stdio functions block each other in a multithreaded program
Message-ID: <20110126102356.GJ28470@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <57962 DOT 83 DOT 86 DOT 0 DOT 251 DOT 1295983886 DOT squirrel AT lavabit DOT com>
MIME-Version: 1.0
In-Reply-To: <57962.83.86.0.251.1295983886.squirrel@lavabit.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Jan 25 14:31, cornwarecjp AT lavabit DOT com wrote:
> I am trying to make a multi-threaded application, where one thread reads
> commands from stdin, and another thread is doing other things, such as
> reading files and printing messages to stdout.
> 
> The problem I have is that the thread that reads files and writes to stdout
> locks while the other thread is reading from stdin. To demonstrate this,
> I created a small program that has this behavior. The C-code is present at
> the end of this e-mail.
> [...]

Thanks for the testcase!

First of all, I can confirm your observation and your testcase easily
allows to debug what happens.  What happens is that the read operation
in scanf and the read operation in fgetc are blocking each other out
because they access the same global lock.

I could track down this behaviour to a specific change in newlib from
2009, which also explains why this still worked in 1.5 (which I tested
as well).

So, the next task for me is to find out why this change has been made
and to talk to the contributor of the change to come to a solution
which does not show this unfortunate behaviour.

What you can do for the time being is to use the low-level IO functions
read and write, rather than the stdio functions fgetc and putchar, since
only the stdio functions are affected by this.

I hope to find a solution soon and the bugfix will definitely be in 1.7.8.

Again, thanks for testcase.  It's highly appreciated.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019