#Noob question: Why doesn't the tokio mutex have a poisoned state?

11 messages · Page 1 of 1 (latest)

gentle ice
#

Hi, I looked at the code of the tokio mutex, but I can't figure out why it doesn't support poison.

vestal dune
#

honestly, Tokio Mutex is incredibly slow already, you should probably be using std's Mutex. (Tokio's Mutex documentation also says so.)

calm bane
#

I could be wrong here but i think tokio::sync::Mutex doesn't acutally get a lock. It as every blocking api yeilds back and waits for Mutex to be free, so if you aquire a lock you actually don't, so panicing in a thread where you tried to do so will not get mutex poisoned

#

Actually after a quick glance over source code i've found a semaphore which looks like a pool

/// An asynchronous counting semaphore which permits waiting on multiple permits at once.
pub(crate) struct Semaphore {
    waiters: Mutex<Waitlist>,
    /// The current number of available permits in the semaphore.
    permits: AtomicUsize,
    #[cfg(all(tokio_unstable, feature = "tracing"))]
    resource_span: tracing::Span,
}

struct Waitlist {
    queue: LinkedList<Waiter, <Waiter as linked_list::Link>::Target>,
    closed: bool,
}
#

I guess if the waker of a thread where you panic is found in a Waitlist it just skips it or have some other mechanism to gracefully handle it. I did not look at the actual implementation, but i think that might be how it works

#

My whole take is probably wrong because there is a guard, but maybe my thoughts will help you in some other way

vestal dune
vapid hemlock
#

lock poisioning was a mistake that should have been removed from the stdlib's locks before 1.0

#

it's a holdover from a much older era where rust was much more go-like with green threading and a large emphasis on message passing across those lightweight threads

#

and poisoning was a way to propagate failures across those threads

gentle ice
#

I still don't really understand why it doesn't have the poisoning mechanism. There are still threads that might have a mutex/lock on the same value. Why wouldn't I want to propagate failure to the other threads? What is the alternative? Use messaging channels?