]> git.lizzy.rs Git - rust.git/commit
std: Reexport std::rt::unwind::try in std::thread
authorAlex Crichton <alex@alexcrichton.com>
Mon, 23 Mar 2015 21:25:56 +0000 (14:25 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 24 Mar 2015 21:53:10 +0000 (14:53 -0700)
commit4c2ddb33ad9e2dbfc3713438472ca85cb5aefd07
treea4b0aca698a6d9d4b3f2b1a5ac45d8c6b55dc96a
parented810385045ab0db90303574ba3ea47dfa2a36d5
std: Reexport std::rt::unwind::try in std::thread

This commit provides a safe, but unstable interface for the `try` functionality
of running a closure and determining whether it panicked or not.

There are two primary reasons that this function was previously marked `unsafe`:

1. A vanilla version of this function exposes the problem of exception safety by
   allowing a bare try/catch in the language. It is not clear whether this
   concern should be directly tied to `unsafe` in Rust at the API level. At this
   time, however, the bounds on `ffi::try` require the closure to be both
   `'static` and `Send` (mirroring those of `thread::spawn`). It may be possible
   to relax the bounds in the future, but for now it's the level of safety that
   we're willing to commit to.

2. Panicking while panicking will leak resources by not running destructors.
   Because panicking is still controlled by the standard library, safeguards
   remain in place to prevent this from happening.

The new API is now called `catch_panic` and is marked as `#[unstable]` for now.
src/libstd/thread/mod.rs