# Skip poison logic for abort on panic

**URL:** <https://internals.rust-lang.org/t/skip-poison-logic-for-abort-on-panic/23795>\
**Category:** libs\
**Created:** [December 5, 2025, 3:31am UTC](https://internals.rust-lang.org/t/skip-poison-logic-for-abort-on-panic/23795 "2025-12-05T03:31:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NobodyXu](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nobodyxu/32/9651_2.png) [@NobodyXu](https://internals.rust-lang.org/u/NobodyXu)\
**Post date:** [December 5, 2025, 3:31am UTC](https://internals.rust-lang.org/t/skip-poison-logic-for-abort-on-panic/23795/1 "2025-12-05T03:31:01Z")

</div>

When looking at threads relared to poison vs no-poison mutex and whether non-poison should be the default, I read a comment suggesting poison isn't needed for abort-on-panic

That reminds me that, all the poison logic/bookkeeper in each poisoned mutex is essentially useless for abort-on-panic and can be removed to free up the space used by them.

So is there any reason we haven't do that yet? Is it because rust will support a c++-compatible external function that allows c/c++ unwinding in a rust function?

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [December 5, 2025, 3:37am UTC](https://internals.rust-lang.org/t/skip-poison-logic-for-abort-on-panic/23795/2 "2025-12-05T03:37:49Z")

</div>

`panic=abort` doesn't abort immediately. It still runs arbitrary user code of the custom panic hook. The hook creates all kinds of re-entrancy complications. In this case the hook could try to access the same mutex (mutex can be reachable from a global variable).

If instead of poisoning, panic left the lock permanently locked, then it would be safe. Re-entrant access from the panic hook would deadlock in the worst case.

---

<div class="post-metadata">

**Author:** ![NobodyXu](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nobodyxu/32/9651_2.png) [@NobodyXu](https://internals.rust-lang.org/u/NobodyXu)\
**Post date:** [December 5, 2025, 3:50am UTC](https://internals.rust-lang.org/t/skip-poison-logic-for-abort-on-panic/23795/3 "2025-12-05T03:50:02Z")

</div>

Thanks for explanation, maybe it would make sense as a build-std feature instead, which wikk automatically enables abort-on-panic

---

<div class="post-metadata">

**Author:** ![chrefr](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@chrefr](https://internals.rust-lang.org/u/chrefr)\
**Post date:** [December 5, 2025, 5:25am UTC](https://internals.rust-lang.org/t/skip-poison-logic-for-abort-on-panic/23795/4 "2025-12-05T05:25:04Z")

</div>

There is such feature (AFAIK it's called `panic_immediate_abort`), but it's mostly used on microcontrollers to avoid the code size bloat, and there we don't have `std` nor `Mutex`.

---

<div class="post-metadata">

**Author:** ![newpavlov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/newpavlov/32/3290_2.png) [@newpavlov](https://internals.rust-lang.org/u/newpavlov)\
**Post date:** [December 5, 2025, 2:03pm UTC](https://internals.rust-lang.org/t/skip-poison-logic-for-abort-on-panic/23795/5 "2025-12-05T14:03:52Z")

</div>

You probably mean [my comment](https://www.reddit.com/r/rust/comments/1pck69k/in_defense_of_lock_poisoning_in_rust_by_sunshowers/nrykl18/?context=3). As you can see in the replies, `Mutex` implements the suggested optimization since Rust 1.78. Unfortunately, to enjoy it currently you have to rely on `-Zbuild-std` (similarly to debug asserts inside `std` methods and function).

---

<div class="post-metadata">

**Author:** ![NobodyXu](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nobodyxu/32/9651_2.png) [@NobodyXu](https://internals.rust-lang.org/u/NobodyXu)\
**Post date:** [December 6, 2025, 1:49am UTC](https://internals.rust-lang.org/t/skip-poison-logic-for-abort-on-panic/23795/6 "2025-12-06T01:49:17Z")

</div>

Thanks! It's unfortunate build-std is unstable and last time I tried it, it gives me strange bug
