Originally Posted by
C progammer
I dont understand you, do you say that it relate to sleep?
Even ehen I edit my c code to , drop out the sleep and put some loops that take time
Paste ofCode
(those loops take about 18 seconds) , I get the "start" only when the c program finish
Curiouser and curiouser. I see the same result, but if I add "fflush(stdout);" directly after the printf I get the start printout after about 3 seconds and then finish when it's done. Forcing stdout to be line buffered made no difference; forcing it to be unbuffered gave me the three-second delay again (using
Code:
setvbuf(stdout, NULL, _IONBF, 0);
to do the forcing).
This code
Code:
#include <iostream>
#include <windows.h>
main()
{
std::cout << "start" << std::endl;
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
for (long i = 0; i < 573123264; i++) {}
std::cout << "finish" << std::endl;
}
however does print "start" immediately for me (compiling with g++ since this classroom doesn't have visual studio in it). Perhaps there's some weird interaction between the old MSVCRT and the new C# stuff? How tied down are you to using C?
EDIT TO ADD: Looking back, that numeric solver I was using above that worked was a C++ program; changing the std::cout to printf's gave me the same wait-until-everything's-done scenario. I'm not sure, though, why RedirectOutput is reading std::cout but not printf.