▲ | jart 7 months ago | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The only way you'd be able to do it is by having functions like fputc() call clock_gettime(CLOCK_MONOTONIC_COARSE) which will impose ~3ns overhead on platforms like x86-64 Linux which have a vDSO implementation. So it can be practical sort of although it'd probably be smarter to just use line buffered or unbuffered stdio. In practice even unbuffered i/o isn't that bad. It's the default for stderr. It actually is buffered in practice, since even in unbuffered mode, functions like printf() still buffer internally. You just get assurances whatever it prints will be flushed by the end of the call. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | asveikau 7 months ago | parent [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|