[erlang-questions] Flush "stdout" buffer

Per Hedeland per@REDACTED
Sun Sep 3 14:51:57 CEST 2017


On 2017-09-03 12:33, Jesper Louis Andersen wrote:
> On Sun, Sep 3, 2017 at 8:30 AM Michael Truog <mjtruog@REDACTED <mailto:mjtruog@REDACTED>> wrote:
> 
> 
>     When you call a function in the io module, what happens?  An io:format/1 function call sends the data in an Erlang message and that Erlang message goes into the group leader's Erlang process
>     message queue, to get received when the Erlang process is ready for it.  That use of the Erlang process message queue is a form of buffering, ignoring everything that happens after that in the
>     group leader Erlang process.
> 
> 
> It is definitely asynchronous communication with latency.
> 
> I don't think it is buffering, however, albeit that is a bit philosophical. As soon as the message arrives, it is sent on. In no place do you delay the write in the hope that more data arrives 
> shortly. If anything it acts like a queue, not a buffer.

Exactly.

So I guess we just have a bit of miscommunication - personally I haven't
previously encountered the use of the term "buffering" for "asynchronous
communication with latency", but I don't know if there is an formal
definition somewhere. However the thread started with the question of
how to do the equivalent of fflush() or "set to unbuffered" for C stdio,
which deals with the stdio buffering that *is* precisely "delay the
write in the hope that more data arrives shortly" - and will delay the
write *forever* in some cases unless you know what you're doing. And
this does not exist in Erlang "standard_io".

But for the question of how to do output with "maximal synchronicity"
and minimal latency, opening a file descriptor port and using
erlang:port_command/2,3 is probably a fine answer.

--Per



More information about the erlang-questions mailing list