rust/src/libstd/task.rs
Aaron Turon a27fbac868 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]
2014-12-18 23:31:52 -08:00

45 lines
1.4 KiB
Rust

// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Deprecated in favor of `thread`.
#![deprecated = "use std::thread instead"]
use any::Any;
use boxed::Box;
use thread;
use kinds::Send;
use result::Result;
use ops::FnOnce;
/// Deprecate: use `std::thread::Builder` instead.
#[deprecated = "use std::thread::Builder instead"]
pub type TaskBuilder = thread::Builder;
/// Deprecated: use `std::thread::Thread::spawn` and `detach` instead.
#[deprecated = "use std::thread::Thread::spawn and detach instead"]
pub fn spawn<F>(f: F) where F: FnOnce(), F: Send {
thread::Thread::spawn(f).detach();
}
/// Deprecated: use `std::thread::Thread::spawn` and `join` instead.
#[deprecated = "use std::thread::Thread::spawn and join instead"]
pub fn try<T, F>(f: F) -> Result<T, Box<Any + Send>> where
T: Send, F: FnOnce() -> T, F: Send
{
thread::Thread::spawn(f).join()
}
/// Deprecated: use `std::thread::Thread::yield_now instead`.
#[deprecated = "use std::thread::Thread::yield_now instead"]
pub fn deschedule() {
thread::Thread::yield_now()
}