News for hackers. Stuff that matters.
Re:We can do better than line-buffered output by jatoo on Friday November 06, 2026 @01:43AM (#50388997)
Doesn't the code as written potentially keep extending the deadline each time the deadline_flush is called even if nothing is written to the buffer? So long as you call the flush often enough which would depend on the work in the while loop.
Re:We can do better than line-buffered output by ahartmetz on Friday November 06, 2026 @07:56AM (#50391772)
Yeah, that is a pitfall one shouldn't fall into even the first time programming something like that - it's pretty obvious, I think? You need to start the deadline timer if it's not running, then keep it running - don't restart it when more input arrives.

Also, this:

> Where DEADLINE is something appropriate for human perception, like 100ms or so

is way off. You easily notice a hitch of one frame in 60 fps content, and this is comparable. The timer should be something like 1-10 ms. Outputting multiple lines is really fast, so even 1 ms would merge most output into a single write() call. I'd start with 1 ms and raise it if there's a strong reason, which there probably isn't.