public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/5298: stream::write
@ 2002-01-08 10:06 Ronald Van Iwaarden
  0 siblings, 0 replies; 4+ messages in thread
From: Ronald Van Iwaarden @ 2002-01-08 10:06 UTC (permalink / raw)
  To: paolo; +Cc: gcc-prs

The following reply was made to PR c++/5298; it has been noted by GNATS.

From: Ronald Van Iwaarden <vaniwaar@ca.metsci.com>
To: <paolo@gcc.gnu.org>,  <gcc-bugs@gcc.gnu.org>,  <gcc-prs@gcc.gnu.org>, 
     <nobody@gcc.gnu.org>,  <paolo@gcc.gnu.org>,  <ron@vaniwaarden.org>, 
     <vaniwaar@ca.metsci.com>,  <gcc-gnats@gcc.gnu.org>
Cc:  
Subject: Re: c++/5298: stream::write
Date: Tue, 8 Jan 2002 09:59:26 -0800 (PST)

 This solved the symptom I described but there is still some funkiness
 going on.  Now, I know what I am describing here is not well defined
 behavior but if take the following program an run it, it always gives
 the same output (up to the order of the lines).  That is, every line is
 printed correctly, but they may come in different orders.  However, if
 you redirect the output to a file, sometimes the output of lines gets
 merged.  I never noted this behavior on the 2.96 compiler...
 
 
 int main()
 {
   std::ios::sync_with_stdio(false);
   int pid= fork();
 
   if (pid){
     cout<<0<<"ARG CALLED: Kind ID = "<<1<<", Data = data "<<endl;
     cout<<2<<"ARG CALLED: Kind ID = "<<1<<", Data = data "
 	<< "p1 = "<<12<<", "<<"p2 = "<<34<<", "<<endl;
     cout<<4<<"ARG CALLED: Kind ID = "<<1<<", Data = data "
 	<< "p1 = "<<12<<", "<<"p2 = "<<34<<", "<<"p3 = "<<56<<", "
 	<<"p4 = "<<78<<", "<<endl;
     cout<<6<<"ARG CALLED: Kind ID = "<<0<<", Data = data "
 	<< "p1 = "<<12<<", "<<"p2 = "<<34<<", "<<"p3 = "<<56<<", "
 	<<"p4 = "<<78<<", "<<"p5 = "<<90<<", "<<"p6 = "<<12<<", "<<endl;
     cout<<8<<"ARG CALLED: Kind ID = "<<0<<", Data = data "
 	<< "p1 = "<<12<<", "<<"p2 = "<<34<<", "<<"p3 = "<<56<<", "
 	<<"p4 = "<<78<<", "<<"p5 = "<<90<<", "<<"p6 = "<<12<<", "
 	<<"p7 = "<<34<<", "<<"p8 = "<<56<<", "<<endl;
   }
   else{
     cout<<1<<"ARG CALLED: Kind ID = "<<1<<", Data = data "
 	<< "p1 = "<<12<<", "<<endl;
     cout<<3<<"ARG CALLED: Kind ID = "<<1<<", Data = data "
 	<< "p1 = "<<12<<", "<<"p2 = "<<34<<", "<<"p3 = "<<56<<", "
 	<<endl;
     cout<<5<<"ARG CALLED: Kind ID = "<<0<<", Data = data "
 	<< "p1 = "<<12<<", "<<"p2 = "<<34<<", "<<"p3 = "<<56<<", "
 	<<"p4 = "<<78<<", "<<"p5 = "<<90<<", "<<endl;
     cout<<7<<"ARG CALLED: Kind ID = "<<0<<", Data = data "
 	<< "p1 = "<<12<<", "<<"p2 = "<<34<<", "<<"p3 = "<<56<<", "
 	<<"p4 = "<<78<<", "<<"p5 = "<<90<<", "<<"p6 = "<<12<<", "
 	<<"p7 = "<<34<<", "<<endl;
   }
 }
 
 run "./a.out > ff; cat ff | sort" and, if run multiple times, you get
 different output.  Note that you get exactly the same output every time
 if you do "./a.out | sort".
 
 Hmmm.  Sorry for the sort of funky description and example...
 
 --Ron
 On 7 Jan 2002 paolo@gcc.gnu.org wrote:
 
 > Synopsis: stream::write
 >
 > Responsible-Changed-From-To: unassigned->paolo
 > Responsible-Changed-By: paolo
 > Responsible-Changed-When: Mon Jan  7 14:15:59 2002
 > Responsible-Changed-Why:
 >     Analyzed.
 > State-Changed-From-To: open->feedback
 > State-Changed-By: paolo
 > State-Changed-When: Mon Jan  7 14:15:59 2002
 > State-Changed-Why:
 >     Hi again Ron!
 >     This one should be easier to solve (I hope): could you
 >     please try adding a:
 >     std::ios::sync_with_stdio(false);
 >     at the beginning of your main?
 >     It works for me (gcc3.0.3 on i686-pc-linux-gnu).
 >
 >     Cheers,
 >     Paolo.
 >
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5298
 >
 
 -- 
 --------------------------------------------------------------------------------
 Ronald Van Iwaarden - Metron Inc. (719)567-9873
 
 main(i){(10-putchar(((25208>>3*(i+=3))&7)+(i?i-4?100:65:10)))?main(i-4):i;}
 
 
 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/5298: stream::write
@ 2002-01-08  9:51 paolo
  0 siblings, 0 replies; 4+ messages in thread
From: paolo @ 2002-01-08  9:51 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, paolo, ron, vaniwaar

Synopsis: stream::write

State-Changed-From-To: feedback->closed
State-Changed-By: paolo
State-Changed-When: Tue Jan  8 09:51:19 2002
State-Changed-Why:
    Submitter privately reports that sync_with_stdio(false),
    the correct, standard-conforming, approach to the issue,
    solves indeed its problem.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5298


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/5298: stream::write
@ 2002-01-07 14:16 paolo
  0 siblings, 0 replies; 4+ messages in thread
From: paolo @ 2002-01-07 14:16 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, paolo, ron, vaniwaar

Synopsis: stream::write

Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Mon Jan  7 14:15:59 2002
Responsible-Changed-Why:
    Analyzed.	
State-Changed-From-To: open->feedback
State-Changed-By: paolo
State-Changed-When: Mon Jan  7 14:15:59 2002
State-Changed-Why:
    Hi again Ron!
    This one should be easier to solve (I hope): could you
    please try adding a:
    std::ios::sync_with_stdio(false);
    at the beginning of your main?
    It works for me (gcc3.0.3 on i686-pc-linux-gnu).
    
    Cheers,
    Paolo.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5298


^ permalink raw reply	[flat|nested] 4+ messages in thread

* c++/5298: stream::write
@ 2002-01-07  7:16 ron
  0 siblings, 0 replies; 4+ messages in thread
From: ron @ 2002-01-07  7:16 UTC (permalink / raw)
  To: gcc-gnats; +Cc: vaniwaar


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-01-08 18:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-08 10:06 c++/5298: stream::write Ronald Van Iwaarden
  -- strict thread matches above, loose matches on Subject: below --
2002-01-08  9:51 paolo
2002-01-07 14:16 paolo
2002-01-07  7:16 ron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).