1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-11-29 08:57:20 +02:00

address feedback 1/2 of @randomPoison

This commit is contained in:
Glen De Cauwsemaecker
2025-08-30 08:12:16 +02:00
parent 48c5baa6f7
commit cc5f3b5af6
2 changed files with 3 additions and 49 deletions

View File

@@ -88,8 +88,7 @@ fn main() -> Result<(), std::io::Error> {
scope.
- Insert `panic!("oops")` at the start of `read_to_end()` to show that `drop()`
still runs during unwinding. Rust guarantees this unless the panic strategy is
set to `abort`.
still runs during unwinding.
- There are cases where destructors will not run:
- If a destructor itself panics during unwinding, the program aborts

View File

@@ -35,19 +35,6 @@ impl<T> Mutex<T> {
}
}
impl<'a, T> std::ops::Deref for MutexGuard<'a, T> {
type Target = T;
fn deref(&self) -> &T {
self.value
}
}
impl<'a, T> std::ops::DerefMut for MutexGuard<'a, T> {
fn deref_mut(&mut self) -> &mut T {
self.value
}
}
impl<'a, T> Drop for MutexGuard<'a, T> {
fn drop(&mut self) {
// [...]
@@ -59,8 +46,8 @@ fn main() {
let m = Mutex::new(vec![1, 2, 3]);
let mut guard = m.lock();
guard.push(4);
guard.push(5);
guard.value.push(4);
guard.value.push(5);
println!("{guard:?}");
}
```
@@ -96,36 +83,4 @@ fn main() {
- On the next `lock()`, this shows up as an error. The caller must decide
whether to proceed or handle the error differently.
- See this example showing the standard library API with poisoning:
<https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=6fb0c2e9e5cbcbbae1c664f4650b8c92>
### Mutex Lock Lifecycle
```bob
+---------------+ +----------------------+
| Mutex<T> | lock | MutexGuard<T> |
| Unlocked | ------> | Exclusive Access |
+---------------+ +----------------------+
^ | drop
| no |
+---------------+ |
| |
| V
+---------------+ yes +-------------------+
| Mutex<T> | <---- | Thread panicking? |
| Poisoned | +-------------------+
+---------------+
|
| lock
|
v
+------------------+
| Err ( Poisoned ) |
+------------------+
```
</details>