3 ms·
How does erlang/elixir do it? I've never really had any problems.
by dnautics 9y ago
How does erlang/elixir do it? I've never really had any problems.
- SlySherZ 9y agoElixir newbie here. If I remember correctly IO is implemented as a process, which means that different write requests are processed sequentially in the order they arrive to the process. The following link has more information: http://erlang.org/doc/apps/stdlib/io_protocol.html http://erlang.org/doc/apps/stdlib/io_protocol.html
- phoe-krk 9y agoCorrect. Erlang (and therefore Elixir) stdio is implemented by means of sending messages to a process that does low-level writing to a console. When a single message is served, the other are queued up. Therefore, when two processes (let's name them A and B) want to output something at the same time, the result is going to be AAAABBBB or BBBBAAAA (depending on the order in which the messages arrive in the mailbox), but never BBAABBAA or anything similar.
- gmfawcett 9y ago...where "AAAA" and "BBBB" are two distinct messages, and not two sets of four messages each ("A", "A", "A", "A"). When I first read your example, it sounded like you were saying that the IO process would exhaust all messages from one source process before processing any messages from the other, no matter what order they arrived in.
- phoe-krk 9y agoYes, correct. I wasn't clear enough.
- amelius 9y agoIt's very customary to let logging and such be done by a separate thread; this has also the benefit that the original (sending) thread can continue without waiting for the device.
- leshow 9y agoThey have a single process which manages IO, you communicate w/ it by passing messages. There is never any contention because it's never shared. Of course, there are trade-offs involved with this decision, but it's a really nice architecture.