Hacker News new | past | comments | ask | show | jobs | submit login

> Erlang chose immutability for safety, while Go chose shared mutable state for practical reasons, but as a remedy Go recommends best practices to avoid the drawbacks caused by it.

That's my point. I didn't say it clearly before. I understand why shared state is bad in general. I don't understand if channel takes care of most scenarios why it's still one of biggest problem for Go listed by author.

> Erlang's reduction-based scheduling does not have this problem and can be very fair.

What's the key difference between Erlang's reduction based scheduling and cooperative scheduling?




> What's the key difference between Erlang's reduction based scheduling and cooperative scheduling?

Cooperative scheduling is like reference-counting: you have to tell the compiler when it's safe to context-switch. Preemptive scheduling is like garbage-collection: the runtime decides on its own when it will switch, and you have to deal with making that safe.

Reduction-based scheduling is a hybrid approach, and is, in this analogy, a bit like Objective-C's Automatic Reference Counting. Under reduction-based scheduling, context switches are a possible side-effect of exactly one operation: function calls/returns. This means that it's very easy to reason about when context switches won't happen (so it's not hard to write atomic code), while not having to worry about making them happen yourself (because, in a language that defines looping in terms of recursion, all code-paths have a known-finite sequence of steps before either a function call or a return.)


Very clear. The reduction based scheduling certainly looks interesting. Thanks for your explanation!


If you only share state by passing messages you should be fine. The challenge is to make sure the "only" part.

Erlang's reduction-based scheduling basically counts how many steps each process has executed, and automatically switches to other processes once a process has finished a certain number of reductions. So even if a process is running tight loops, it would not starve other processes. Go's scheduler currently cannot promise that.


Another way to put it: you can write the equivalent of

    while (true) { do some stuff }
in Erlang and it will not hang the system.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: