简体   繁体   中英

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.

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

By default Rust uses native threading, and you can't just disable it. 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.

It is possible to disable green threading, but Rust does not use it by default for a long time already. 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. This is the default mode of operation of Go, for example. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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