c++ - Read and Write to Windows pipes in separate threads -
in program start thread redirect output console:
while(true) { if (!readfile(hpiperead,lpbuffer,sizeof(lpbuffer), &nbytesread,null) || !nbytesread) { if (getlasterror() == error_broken_pipe) break; // pipe done - normal exit path. else displayerror("readfile"); // bad happened. } // display character read on screen. if (!writeconsole(getstdhandle(std_output_handle),lpbuffer, nbytesread,&ncharswritten,null)) displayerror("writeconsole"); }
the problem is loop. possible to avoid run of loop making thread wait until appears in pipe?
the problem becomes more intense when there analogous thread writing.
Comments
Post a Comment