pub struct Handle { /* private fields */ }Expand description
A thread-local handle to the garbage collector.
Obtain one with handle(). A Handle is cheap to clone
(it is reference-counted) and serves two purposes:
- Accessing the managed heap. Call
pin()to get aGuardthat lets you allocate, load, and dereference managed pointers. - Extending pointer lifetimes. Pass it to
Local::protectto keep a reference alive past itsGuardwith hazard-pointer protection.
§Examples
let handle = handle();
let guard = handle.pin();
let node = Local::new(Node { value: 1 }, &guard);
let kept = node.protect(&handle); // outlives the guard
drop(guard);
assert_eq!(kept.value, 1);Implementations§
Source§impl Handle
impl Handle
Sourcepub fn pin(&self) -> Guard
pub fn pin(&self) -> Guard
Returns a Guard that grants access to the managed heap.
While the guard is alive, you may allocate managed objects, load atomic
pointers, and freely dereference any Local obtained
from those loads. Internally, this pins the current thread to the global
epoch (entering a phase-critical section).
§Examples
let handle = handle();
let guard = handle.pin();
// ... access the managed heap through `guard` ...
drop(guard);Sourcepub fn help_collect(&self)
pub fn help_collect(&self)
Voluntarily assists the collector with pending work.
Useful in long-running threads that rarely allocate: calling it periodically helps the collector make progress. It pins the thread briefly for the duration of the call.
§Examples
let handle = handle();
handle.help_collect();Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Handle
impl !Send for Handle
impl !Sync for Handle
impl !UnwindSafe for Handle
impl Freeze for Handle
impl Unpin for Handle
impl UnsafeUnpin for Handle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more