pub struct PinGuard<'a, T: 'static> { /* private fields */ }Expand description
A guard that keeps the current thread pinned to a version.
PinGuard is obtained by calling LocalReader::pin().
It implements Deref<Target = T> to allow reading the current value.
It is !Send and !Sync because it references a !Sync LocalReader.
Its lifetime is bound to the LocalReader it came from.
While a PinGuard is held, the thread is considered “active” at a particular version,
and the garbage collector will not reclaim data from that version.
PinGuard supports internal cloning via reference counting (increments the pin count),
allowing nested pinning. The thread remains pinned until all cloned guards are dropped.
Safety: The PinGuard is the mechanism that ensures safe concurrent access to
shared values. Readers must always hold a valid PinGuard when accessing
shared data.
一个保持当前线程被钉住到一个版本的守卫。
PinGuard 通过调用 LocalReader::pin() 获得。
它实现了 Deref<Target = T>,允许读取当前值。
它是 !Send 和 !Sync 的,因为它引用了一个 !Sync 的 LocalReader。
它的生命周期被绑定到它来自的 LocalReader。
当 PinGuard 被持有时,线程被认为在特定版本“活跃“,
垃圾回收器不会回收该版本的数据。
PinGuard 支持通过引用计数的内部克隆(增加 pin 计数),允许嵌套 pinning。
线程保持被钉住直到所有克隆的守卫被 drop。
安全性:PinGuard 是确保对值安全并发访问的机制。
读者在访问共享数据时必须始终持有有效的 PinGuard。
Implementations§
Trait Implementations§
Source§impl<'a, T> Clone for PinGuard<'a, T>
impl<'a, T> Clone for PinGuard<'a, T>
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clone this guard to create a nested pin.
Cloning increments the pin count, and the thread remains pinned until all cloned guards are dropped. This allows multiple scopes to hold pins simultaneously.
克隆此守卫以创建嵌套 pin。
克隆会增加 pin 计数,线程保持被钉住直到所有克隆的守卫被 drop。 这允许多个作用域同时持有 pin。
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more