Revise std::thread API to join by default
This commit is part of a series that introduces a `std::thread` API to replace `std::task`. In the new API, `spawn` returns a `JoinGuard`, which by default will join the spawned thread when dropped. It can also be used to join explicitly at any time, returning the thread's result. Alternatively, the spawned thread can be explicitly detached (so no join takes place). As part of this change, Rust processes now terminate when the main thread exits, even if other detached threads are still running, moving Rust closer to standard threading models. This new behavior may break code that was relying on the previously implicit join-all. In addition to the above, the new thread API also offers some built-in support for building blocking abstractions in user space; see the module doc for details. Closes #18000 [breaking-change]
This commit is contained in:
@@ -102,7 +102,11 @@ struct Output {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
std::os::set_exit_status(main_args(std::os::args().as_slice()));
|
||||
static STACK_SIZE: uint = 32000000; // 32MB
|
||||
let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || {
|
||||
main_args(std::os::args().as_slice())
|
||||
}).join();
|
||||
std::os::set_exit_status(res.map_err(|_| ()).unwrap());
|
||||
}
|
||||
|
||||
pub fn opts() -> Vec<getopts::OptGroup> {
|
||||
@@ -343,7 +347,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
|
||||
let cr = Path::new(cratefile);
|
||||
info!("starting to run rustc");
|
||||
|
||||
let (mut krate, analysis) = std::thread::Thread::with_join(move |:| {
|
||||
let (mut krate, analysis) = std::thread::Thread::spawn(move |:| {
|
||||
let cr = cr;
|
||||
core::run_core(libs, cfgs, externs, &cr, triple)
|
||||
}).join().map_err(|_| "rustc failed").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user