I came across your question when researching a problem I have on Windows.
I have a command line program that has 2 threads, one for reading data, and the other for writing it (in a queue).
Every 30 seconds the reader (the initial process) writes out a progress message and was appearing to hang, so I hit Ctrl-C once and found out that my program was actually continuing (Ctrl-C once did not kill it).
Anyway, while try to work out what was going on, I started another console window and ran the command:
for /l %g in () do @(dir & timeout /t 2)
Every once in a while it would lock up too, and a Ctrl-C would free it up.
There appears to be some sort of bug in Windows where when the system is otherwise really busy the Sleep function does not return (Ctrl-C seems to unlock it).
Anyway, hope that helps someone.
fflush(stdio);
on every iteration? – Equitation