Wed Sep 17 17:57:00 GMT 2003
The issue appears related to the use of the pthread
library, where is almost appears if every thread now
has its own streams buffer, rather then a shared
buffer as the threading model dictates.
In the belowlisted sample, the 'main' thread creates a
logger thread which issues the setvbuf and
subsequently signals a condition that the main thread
is waiting on.
When the main thread resumes and it issues printf()'s
these are not line buffered as requested in the logger
The test case should display test1 and test 2, wait
for 5 seconds and then display test2, instead it
displays test 1, then is waits, then test2 and test3
are displayed, eventhough there is no sleep between
test 1 and test 2.
What is not in this testcase, is that any printf()
from any other thread is not line buffered once again,
so the it appears that the buffering indicator has
become thread dependent, rather then stream dependent.
static pthread_attr_t logger_attr;
static pthread_cond_t logger_cond;
static pthread_mutex_t logger_lock;
static pthread_t logger_tid;
static int pipefd;
void *logger_thread(void *arg)
setvbuf(stdout, NULL, _IOLBF, 0); // *** THIS DOES
NOT WORK PROPERLY ***
n = read(pipefd, buffer, sizeof(buffer));
buffer[n] = '\0';
pthread_create (&logger_tid, &logger_attr,
//setvbuf(stdout, NULL, _IOLBF, 0);
From: Christopher Faylor <cgf-rcm at cygwin dot com>
To: cygwin at cygwin dot com
Date: Tue, 16 Sep 2003 16:04:00 -0400
Subject: Re: setvbuf/setlinebuf issue
Reply-to: cygwin at cygwin dot com
On Tue, Sep 16, 2003 at 12:13:31PM -0700, Jan Jaeger
>We have always used setvbuf(stdout, NULL, _IOLBF, 0)
to ensure that
>each line is read by the logger as it is written.
>However this has now stopped working in the current
release of cygwin,
>adding a fflush() after every printf() bypasses the
error, but at the
>moment setvbuf does not seem to work correctly for
Do you have a simple test case which demonstrates
this? I wrote the
below and piped it into cat and it works as expected.
"foo" is printed,
there is a five second pause, and "bar is printed.
main (int argc, char **argv)
setvbuf(stdout, NULL, _IOLBF, 0);
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
More information about the Cygwin