36
you are viewing a single comment's thread
view the rest of the comments
[-] TehPers@beehaw.org 2 points 1 day ago

I'm having trouble finding any popular alternative implementations of Mutex that support poisoning. parking_lot, tokio, and futures all have non-poisoning (possibly async) mutexes.

In fact, there's almost no argument for requiring poisoning. There are some fringe cases where poisoning is useful, and in those cases, you could just as easily create a Poisoning<T> pointer that implements it.

As the article says, no other built-in pointer type in Rust support poisoning, yet the same "invalid state" argument can be made for all of them. A &mut T can become temporarily "invalid" (in a sound manner) during a critical block that panics, for example. That pointer could be mutating data that's eventually dropped during unwinding, does not hold its invariants at this time, and triggers a Drop impl that's unsound as a result. At the end of the day, the correct way to handle this is to somehow either fix the state during unwinding so that it no longer violates an invariant, or mark it as poisoned, regardless of pointer type.

The only real argument for poisoning by default is because it already is the default. It's a strong argument of course (it would likely be a breaking change to remove it), but it's not a very solid argument for why it should be a default to begin with.

[-] BB_C@programming.dev 1 points 1 day ago

I’m having trouble finding any popular alternative implementations of Mutex that support poisoning.

https://docs.rs/saa/5.6.4/saa/lock/struct.Lock.html

[-] TehPers@beehaw.org 1 points 1 day ago* (last edited 1 day ago)

I'm confused by this. saa::Lock does support poisoning, but it appears to be manual. You need to both manually mark it as poisoned via lock.poison_lock() and manually check if it's poisoned with the return value from locking. You can easily ignore poisoning entirely - it's actually more opt-in rather than forced on you. So sure this supports poisoning, but it's not forced on you like std::sync::Mutex, and saa::Lock isn't anything close to a complete Mutex alternative anyway.

It seems to support lock_api apparently (presumably as the locking implementations behind it?), but lock_api::Mutex doesn't appear to support poisoning at all.

this post was submitted on 18 Nov 2026
36 points (100.0% liked)

Rust

8379 readers
30 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 3 years ago
MODERATORS