Live data from Hacker News

Haskell's Missing Concurrency Basics (2016)

snoyman.com

1–10 of 27 posts

Re: Haskell's Missing Concurrency Basics (2016)

#5
post #4

How does erlang/elixir do it? I've never really had any problems.

Elixir 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

Re: Haskell's Missing Concurrency Basics (2016)

#6
post #2

Thread-unsafe `println` is one of Clojure's quirks too!

Interesting, I think it's thread-safe in Rust because one of the common performance improvements for console applications with lots of output is to acquire the relevant stream's lock (and perform all writes against a never-released guard) otherwise it's going to be acquired and dropped on every write: https://doc.rust-lang.org/src/std/io/stdio.rs.html#448-461

Re: Haskell's Missing Concurrency Basics (2016)

#7
post #5
post #4

How does erlang/elixir do it? I've never really had any problems.

Elixir 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

Correct. 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.

Re: Haskell's Missing Concurrency Basics (2016)

#8
post #5
post #4

How does erlang/elixir do it? I've never really had any problems.

Elixir 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

It'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.

Re: Haskell's Missing Concurrency Basics (2016)

#9
post #7
post #5

Earlier quoted context omitted.

Elixir 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

Correct. 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), bu…

...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.

Re: Haskell's Missing Concurrency Basics (2016)

#10
Use an STM channel or some other lock and put your messages for the shared resource (the terminal ui) through that channel. There’s no way to automatically figure out what granularity the programmer expects from the output so make them specify. Haskell makes specifying that staggeringly easy compared to other languages.
Post reply on HN