mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
reactor: use LocalKey::try_with in sharded RW lock (#628)
@jonhoo reported a panic in the call to `LocalKey::with`, which occurs when the reactor is dropped in the middle of TLS teardown. This PR changes the call to `LocalKey::try_with` and handles the case when the thread-local value has already been destroyed.
This commit is contained in:
parent
19d5565442
commit
0f44adf5f6
@ -150,11 +150,12 @@ impl<'a, T> DerefMut for RwLockWriteGuard<'a, T> {
|
||||
|
||||
/// Returns a `usize` that identifies the current thread.
|
||||
///
|
||||
/// Each thread is associated with an 'index'. While there are no particular guarantees, indices
|
||||
/// usually tend to be consecutive numbers between 0 and the number of running threads.
|
||||
/// Each thread is associated with an 'index'. Indices usually tend to be consecutive numbers
|
||||
/// between 0 and the number of running threads, but there are no guarantees. During TLS teardown
|
||||
/// the associated index might change.
|
||||
#[inline]
|
||||
pub fn thread_index() -> usize {
|
||||
REGISTRATION.with(|reg| reg.index)
|
||||
REGISTRATION.try_with(|reg| reg.index).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// The global registry keeping track of registered threads and indices.
|
||||
|
Loading…
x
Reference in New Issue
Block a user