This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/5298: stream::write
- From: ron at vaniwaarden dot org
- To: gcc-gnats at gcc dot gnu dot org
- Cc: vaniwaar at ca dot metsci dot com
- Date: 7 Jan 2002 15:06:02 -0000
- Subject: c++/5298: stream::write
- Reply-to: ron at vaniwaarden dot org
>Number: 5298
>Category: c++
>Synopsis: stream::write
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jan 07 07:16:02 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Ronald Van Iwaarden
>Release: gcc version 3.0.2 20010905 (Red Hat Linux 7.1 3.0.1-3)
>Organization:
>Environment:
Redhat Linux version 7.2 with g++3 installed.
>Description:
ostreams now flush() after every call to ostream::write(char*, int) because the write() call calls sync() which, in turn, calls flush(). This is a change from prior versions and other compilers. The prior behavior was to flush at every endl. This behavior can significantly degrade performance of IO, not to mention, results in unexpected behavior.
I don't know if this is actually a bug but it certainly caught me off guard and is going to prevent use of g++ version 3.0 without significant modifications to our code...
>How-To-Repeat:
Execute the following program on an OS that supports fork(). On g++ 2.9.*, it would print out
3.1416
3.1416
but on 3.0.2, it prints out
33..1411461
6
or other slight variations on the order because of timing issues:
#include <iostream.h>
#include <unistd.h>
int main()
{
int pid= fork();
if (pid) sleep(1);
cout.write("3", 1); sleep(1);
cout.write(".", 1); sleep(1);
cout.write("1", 1); sleep(1);
cout.write("4", 1); sleep(1);
cout.write("1", 1); sleep(1);
cout.write("6", 1); sleep(1);
cout.write("\n", 1); sleep(1);
}
>Fix:
Not sure except that I don't think the stream should flush after every write call...
>Release-Note:
>Audit-Trail:
>Unformatted: