I have a C++ program that contains several cout
statements. I have ensured that all of them end with an endl
. My problem is that the program seldom halts until a user presses Enter (so I assume that the output buffer isn't always flushed as it should). Pressing enter resumes program execution. This is quite problematic as my program takes several hours to execute, so I can't afford to press enter all the time! Note that sometimes the program halts after a minute and other times after more than an hour.
Here's a small code snippet:
for(int i = 0; i < _numIterations; i++){
std::cout << "Iteration " << i << std::endl;
// Computations and more print statements.
}
Note that I use Theano through embed Python, and that my Python code also contains print statements. My Python code only calls print, not sys.stdout.flush()
after each print. However, it is rare that the program execution hangs after a Python-generated print statement. Have I missed something obvious? Should I make a call to sys.stdout.flush()
in the Python code? Unfortunately, I cannot provide more code as my program consists of dozens of classes.
[Edit] I've paused the program with a debugger when it was hanging, and no source was available to be displayed. The call stack was:
It seems that a thread is waiting. However, I have not set up these threads myself. They were either generated by Cuda or the Havok physics engine that I'm also using. I'll investigate.