delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/01/28/06:41:51

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Fri, 28 Jan 2011 12:41:25 +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: <20110128114125.GV28470@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> <20110126102356 DOT GJ28470 AT calimero DOT vinschen DOT de>
MIME-Version: 1.0
In-Reply-To: <20110126102356.GJ28470@calimero.vinschen.de>
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 26 11:23, Corinna Vinschen wrote:
> 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.

After some discussion with my newlib co-maintainer I checked in a patch
which should solve your problem.  Your testcase works fine for me now
when using the latest developer snapshot(*) from today.

Please give it a test in your environment.


Thanks,
Corinna

(*) http://cygwin.com/snapshots/

-- 
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