简体   繁体   English

如何在Rust中禁用并行执行?

[英]How to disable parallel execution in Rust?

I need to prevent some programs from running in parallel (last time I checked there was RUST_THREADS=1 option but can't find any docs for it) because they screw up the display. 我需要防止某些程序并行运行(上次我检查是否有RUST_THREADS=1选项,但找不到任何文档),因为它们搞砸了显示。

I'm running a program from cargo, but I'd prefer to do it for executive form of program (ie instead of cargo run I could use ./myprogram ). 我正在从货运运行程序,但我更喜欢以执行程序形式执行该程序(即代替cargo run我可以使用./myprogram )。

By default Rust uses native threading, and you can't just disable it. 默认情况下,Rust使用本机线程,您不能只禁用它。 It just doesn't make sense and will almost certainly break multithreaded program completely - it is because native thread scheduling is done by OS, so hypothetical "disabling" of native threading will leave all programs with their main thread only. 只是没有意义,几乎可以肯定会完全破坏多线程程序-这是因为本机线程调度是由OS完成的,因此假设“禁用”本机线程将使所有程序仅保留其主线程。

It is possible to disable green threading, but Rust does not use it by default for a long time already. 可以禁用绿色线程,但是Rust默认情况下已经很长时间不使用它了。 This is possible because green threads rely on user-land scheduler, usually implemented in a language runtime, and it usually can be configured to use single OS thread. 这是可能的,因为绿色线程依赖于通常在语言运行时中实现的用户区域调度程序,并且通常可以将其配置为使用单个OS线程。 This is the default mode of operation of Go, for example. 例如,这是Go的默认操作模式。 Rust switched to native threading as it is closer to underlying OS, more effective and much easier to implement and support, so RUST_THREADS does not work anymore (even if it ever worked). 由于Rust更接近底层操作系统,更有效且更易于实现和支持,因此切换到本机线程,因此RUST_THREADS不再起作用(即使它曾经起作用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM