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 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 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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 Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , 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