rust-lang/rust — pull request #19661 by alexcrichton (2014-12-09 15:39:27+00:00)
Title: std: Return Result from RWLock/Mutex methods

All of the current std::sync primitives have poisoning enable which means that
when a task fails inside of a write-access lock then all future attempts to
acquire the lock will fail. This strategy ensures that stale data is never
viewed by other tasks to assist with exception safety.

Currently there is no way to test whether a mutex or rwlock is poisoned. One
method would be to duplicate all the methods with a sister foo_catch function,
for example. This pattern is, however, against our [error guidelines][errors].
As a result, this commit exposes the fact that a task has failed internally
through the return value of a `Result`. Each error type returned implements
`Show`, `Error`, and `FromError` where possible to assist in usage of
`.unwrap()` and `try!` for these errors.

[errors]: https://github.com/rust-lang/rfcs/blob/master/text/0236-error-conventions.md#do-not-provide-both-result-and-fail-variants