You can avoid this by doing something like:
setvbuf(stdout, NULL, _IONBF, 0);
https://sourceware.org/git/?p=glibc.git;a=blob;f=stdio-commo...