▲ | asveikau 7 months ago | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I think doing those timeouts transparently would be tricky under the constraints of POSIX and ISO C. It would need to have some cooperation from the application layer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | jart 7 months ago | parent [-] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|