It would complicate the runtime for an uncommon case. Also, how would this work? Does every writable FILE* get this treatment? Or only stdout? How is it implemented? How do I opt in/out? At the source level? At runtime?
In general, because that would require a background thread or interrupt that would flush the output. *NIX libcs, in general, do not create threads for internal use because the existence of threads leaks too easily and causes problems.
On some systems, especially VMs, you get something like this for free. The file descriptor equivalent had a ring buffer that the other side can periodically poll. You write into it and then increase the producer counter. If the buffer is full, you may do a synchronous call to block until the output has been consumed. I think you can probably do the same with io_urging on Linux, but I don’t think any libc uses it for FILE*.
Why not have a fully buffered option that still flushes every so many milliseconds?
It would complicate the runtime for an uncommon case. Also, how would this work? Does every writable FILE* get this treatment? Or only
stdout
? How is it implemented? How do I opt in/out? At the source level? At runtime?In general, because that would require a background thread or interrupt that would flush the output. *NIX libcs, in general, do not create threads for internal use because the existence of threads leaks too easily and causes problems.
On some systems, especially VMs, you get something like this for free. The file descriptor equivalent had a ring buffer that the other side can periodically poll. You write into it and then increase the producer counter. If the buffer is full, you may do a synchronous call to block until the output has been consumed. I think you can probably do the same with io_urging on Linux, but I don’t think any libc uses it for FILE*.
I see, thanks. Also, io_urging is going to be the name of my next band.
I broke my shoulder last week and am typing one handed, if anyone’s wondering why autocorrect seems to be picking on me recently.
*cough* glibc aio :)
It would be convenient if glibc did not fully-buffer the first 10
fwrite
calls per second.