I think, that it's not...
I first used
// Redirect "stdout" to the console window.
AllocConsole();
fclose(stdout);
setbuf(stdout, NULL);
*stdout = *_fdopen(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), 0), "w");
for debugging output. That causes conflicts when two threads try to write in it (deadlock).
With three other variants there are no deadlocks:
1) Opening a log file and write via fprintf.
2) Preparing the string via sprinft and output through OutputDebugString.
3) Having a console (AllocConsole) too, but prepare the string via sprintf and write to the console via WriteFile.
The problems seems to be the access right to the console output with a redirected handle for printf (to stdout).
I'm not sure if it's worth the time, since *stdout = *_fdopen(_open_osfhandle(...
is a hard workaround, not Ansi C and not possible with all compilers. To me, _fdopen seems to erase the "share write" flag...
If this is good behaviour, I'm not shure...
I sent you some example source to try.
Regards,
Andreas