This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/5298: stream::write



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




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]