▲ | asveikau 7 months ago | |||||||||||||||||||||||||||||||||||||||||||||||||
That's just for checking the clock. You'd also need to have a way of getting called back when the timeout expires, after fputc et al are long gone from the stack and your program is busy somewhere else, or maybe blocked. Timeouts are usually done with signals (a safety nightmare, so no thanks) or an event loop. Hence my thought that you can't do it really transparently while keeping current interfaces. | ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | jart 7 months ago | parent [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
Signals aren't a nightmare it's just that fflush() isn't defined by POSIX as being asynchronous signal safe. You could change all your stdio functions to block signals while running, but then you'd be adding like two system calls to every fputc() call. Smart thing to do would probably be creating a thread with a for (;;) { usleep(10000); fflush(stdout); } loop. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|