1 Jan 2009 21:53
Re: Data printed to pipe sometimes comes out twice
Gábor Melis <mega <at> retes.hu>
2009-01-01 20:53:06 GMT
2009-01-01 20:53:06 GMT
On Viernes 19 Diciembre 2008, Rudi Schlatte wrote: > On 19.12.2008, at 20:33, Gábor Melis wrote: > > On Viernes 19 Diciembre 2008, Tim Cooijmans wrote: > >> I have two threads that communicate through a two-way pipe. This > >> mostly works, but sometimes I get weird buggy behaviour, where > >> something that's written into the pipe comes out twice at the > >> other end. > >> > >> Attached is a minimal test case. The main thread reads from stdin > >> and prints whatever is read to a pipe. The other thread reads > >> from the other end of the pipe and prints whatever comes out. > >> Feed it some input and you might see the second thread read the > >> same input twice. > >> > >> What could cause this? My code looks good to me. Thread-safety > >> shouldn't matter because the threads never read from or print to > >> the same streams simultaneously (right?). Can anyone reproduce > >> this or is it just me? > >> > >> Thanks, > >> > >> Tim > > > > I think it ought to be fine, however it fails here, as well. > > > > The root of the problem is that the two way stream itself will, for > > some > > reason, flush its OUT each time its IN is read (!), hence the > > internal buffer is modified concurrently by two threads. > >(Continue reading)
RSS Feed