libgreen 怎么了?

What happened to libgreen?

据我了解 libgreen is not a part of Rust standard library anymore. Also I can't find a separate libgreen package. There are a few alternatives - coroutine, which does not provide actual green threads for now, and green-rs,它已损坏。我是否正确理解,目前 Rust 中没有类似 Go 的轻量级进程?

std(或其他主要发行版)中没有轻量级任务库,green 无法编译且 coroutine 无法编译,您是对的似乎还没有完全处理线程方面。我不知道这个 space.

中的任何其他图书馆

至于发生了什么:该问题链接到的 RFC——RFC 230——是规范的信息来源。总结是,人们发现处理绿色 threading/IO 的方法(std 试图对两个模型进行抽象,允许它们自动地互操作使用)不值得缺点。现在,std 旨在提供最低限度的有用支持基线:对于 IO/threading,这意味着 "thin",操作系统功能的安全包装器。

阅读此 https://aturon.github.io/blog/2016/08/11/futures/ 以及:

Steve Klabnik's response 在评论中:

In the beginning, Rust had only green threads. Eventually, it was decided that a systems language without systems threads is... strange. So we needed to add them. Why not add choice? Since the interfaces could be the same, why not abstract over them, and you could just choose which one you wanted?

At the same time, the problems with green threads by default were becoming issues. Segmented stacks cause slow C interop. You need a runtime to manage them, etc. Furthermore, the overall abstraction was causing an unacceptable cost. The green threads weren't very green. Plus, with the need to actually release someday looming, decisions needed to be made regarding tradeoffs. And since Rust is supposed to be a systems language, having 1:1 threads and basically no runtime makes more sense than N:M threads and a runtime. . So libgreen was removed, the interface was re-done to be 1:1 thread centric.


The 'release someday looming' is a big part of it. We want to be really stable with Rust, and with all the things to do to actually ship a 1.0, we didn't want to crystallize an interface we weren't happy with. Heck, we pulled out a lot of libraries that are even less important for similar reasons, like rand. Engineering is all about tradeoffs, and we decided to choose minimalism.

mio is a non starter for us, as are most of the other async i/o frameworks for Rust, because we need Windows and besides we don't want to get locked into an expensive to replace library which may get orphaned.

这里完全理解,尤其是在一般情况下。在里面 具体情况,mio 要么有 Windows 支持,要么 windows-特定版本的 mio 即将发布,带有 为所有平台提供功能的更高级别的包。而在 在这种情况下,它由当前正在使用的人之一维护 生产中生锈严重,所以它不太可能随时消失 很快。但是,除非你积极参与,否则很难知道事情 像这样,这本身就是一个问题。

我们愿意删除 libgreen 的原因之一是您 可以编写自己的库来执行不同类型的 IO。 1.0是一个 强大的核心,我们对永远稳定而不是最终稳定感到满意 少量。 https://github.com/carllerche/mio之类的库可以测试出来 处理诸如异步 IO 之类的事情的不同方式,以及何时 足够成熟,如果 需要。但与此同时,它只是您 Cargo.toml 的一行 把它们加进去。

这样 text from reddit:

Unfortunately they ended up canning the greenlet support because theirs were slower than kernel threads which in turn demonstrates someone didn’t understand how to get a language compiler to generate stackless coroutines effectively (not surprising, the number of engineers wired the right way is not many in this world, but see http://www.reddit.com/r/rust/comments/2l0a4b/do_rust_web_servers_use_libuv_through_libgreen_or/ for more detail). And they canned the async i/o because libuv is “slow” (which it is only because it is single threaded only, plus forces a malloc + free per async operation as the buffers must last until completion occurs, plus it enforces a penalty over synchronous i/o see http://blog.kazuhooku.com/2014/09/the-reasons-why-i-stopped-using-libuv.html), which was a real shame - they should have taken the opportunity to replace libuv with something better (hint: ASIO + AFIO, and yes I know they are both C++, but Rust could do with much better C++ interop than the presently none it currently has) instead of canning always-async-everything in what could have been an amazing step up from C++ with most of the benefits of Erlang without the disadvantages of Erlang.

对于新手,现在有 may,一个实现类似于 goroutines 的绿色线程的 crate。