Home

PoisonErrorRwLockReadGuardT

PoisonError is a type in the Rust standard library that represents the situation where a synchronization primitive has been poisoned after a thread panicked. In the context of an RwLock (read-write lock), poisoning occurs when a thread panics while holding either the read lock or the write lock. If the lock is poisoned, other threads attempting to acquire the lock receive an error of the form Err(PoisonError<Guard>), where Guard is either a RwLockReadGuard or a RwLockWriteGuard.

A PoisonError conveys that the guarded data may have been left in an inconsistent state due to

Handling strategies vary. Some code propagates the poisoning error to callers, signaling that recovery is needed

Notes for practice: poisoning is per lock, and a lock can become poisoned if a thread panics

the
panic.
The
guard
inside
the
PoisonError
is
the
exact
type
of
access
that
was
poisoned,
enabling
recovery
attempts.
To
reclaim
the
inner
guard,
you
can
call
into_inner
on
the
PoisonError,
returning
the
guarded
value
and
allowing
the
program
to
continue
using
the
data,
typically
after
performing
any
necessary
invariants
checks
or
reinitialization.
at
a
higher
level.
Other
code
chooses
to
recover
locally
by
extracting
the
inner
guard
with
into_inner
and
proceeding,
but
only
after
ensuring
the
data’s
invariants
are
upheld.
In
all
cases,
poisoning
is
a
signal
that
a
panic
occurred
while
holding
the
lock,
and
it
should
influence
how
the
protected
data
is
accessed
subsequently.
while
holding
it.
The
behavior
applies
to
both
read
and
write
guards
of
an
RwLock,
reflecting
the
exact
access
that
was
poisoned.