Function coco::epoch::pin [] [src]

pub fn pin<F, T>(f: F) -> T where
    F: FnOnce(&Scope) -> T, 

Scopes the current thread.

The provided function takes a reference to a Scope, which can be used to interact with Atomics. The pin serves as a proof that whatever data you load from an Atomic will not be concurrently deleted by another thread while the pin is alive.

Note that keeping a thread pinned for a long time prevents memory reclamation of any newly deleted objects protected by Atomics. The provided function should be very quick - generally speaking, it shouldn't take more than 100 ms.

Scopening is reentrant. There is no harm in pinning a thread while it's already pinned (repinning is essentially a noop).

Scopening itself comes with a price: it begins with a SeqCst fence and performs a few other atomic operations. However, this mechanism is designed to be as performant as possible, so it can be used pretty liberally. On a modern machine pinning takes 10 to 15 nanoseconds.