Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did Rust remove the green-threading model; what's the disadvantage?

Runtime freedom: Rust’s runtime system and green-threading model has been entirely removed, which cut the static binary size of “hello world” in half and has opened the door to lower-level hooks into the standard library. Implemented by Aaron Turon.

http://blog.rust-lang.org/2015/01/09/Rust-1.0-alpha.html

What's the disadvantage of the green-threading model?

Why is Erlang so fast?

like image 538
acmerfight Avatar asked Apr 03 '15 07:04

acmerfight


People also ask

Does Rust use green threads?

Rust, in fact, has a history with green threads. A green threads runtime used to be the default paradigm for Rust code. Among other reasons (which will be addressed throughout the course of the rest of the paper) the Rust team decided that having a systems language use a green threads runtime did not quite align.

What is green thread model?

Green Thread model Green Thread Model. In this model, threads are completely managed by JVM without any kind of underlying OS support. These threads are implemented at the application level and managed in user space. They are also called cooperative (user-level) threads. Only one green thread can be processed at a time ...

Are green threads faster?

Green threads are significantly faster than native threads when having more active threads than processors. Java initially had support for green threads but unlike most modern green threading implementations it could not scale over multiple processors, making Java unable to utilise multiple cores.

What is thread in Rust?

The threading modelAn executing Rust program consists of a collection of native OS threads, each with their own stack and local state. Threads can be named, and provide some built-in support for low-level synchronization.


1 Answers

Erlang uses green threads with preemption. This is possible only because Erlang has a VM, which also allows a lot of other things like code hotswap. But languages with VM are unsuitable for systems programming because they always have some constant overhead, both in memory and processing power. Rust is a systems programming language, and so it cannot have a significant runtime system. I'd also add that Erlang is not fast. It is notoriously ineffective in numerical computations, for example - see here. Its concurrency model allows for high throughput for I/O operations, but this is a different thing.

So in order to support green threads in a feasible way a language has to have some kind of runtime. The reasons of runtime removal in Rust are outlined in the corresponding RFC. In short, the runtime model used in Rust at that time was difficult to work with efficiently and hard to improve, while not having sufficient benefits due to implementation problems and general constraints due to the API, so it was scrapped. As far as I know, nothing in principle prevents someone from writing a green thread-based runtime for Rust, just no one did that yet.

like image 197
Vladimir Matveev Avatar answered Sep 20 '22 12:09

Vladimir Matveev