简体   繁体   中英

Multiple calls to std::cout make subprocess hang

I'll copy here part of my previous question to describe the problem:

I wrote an application in C++ that has two parts - the frontend and the backend. These two communicate using IPC layer provided by wxWidgets. In the backend I use some legacy functions for image data manipulation. One of these functions hangs or falls into some infinite loop sometimes (I can observe that 0% of the process resources are used by the process after some point), but this happens only if I ran the backend as a subprocess of the frontend. Otherwise (when I run it manually) it works just fine.

It turns out that printing too many lines with std::cout was causing that, but I'd like to understand why. Could it be that wxWidgets utilizes some buffer for storing application output and printing was simply overflowing it? Or this is rather native issue of Windows? Or maybe it could be related to std::cout implementation? I'm pretty sure I'm not able to reproduce this with printf It seems that I was wrong - printf also seems to trigger that issue

The stdout buffer is of a finite size. Something must be reading what you are writing into the buffer, whether this is a file, a console window or another process. If you write faster than the reader is able to cope with then the buffer will eventually fill up and block any further writes until the reader has read some data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM