crossbeam_epoch::Local::pin

Recall that crossbeam_epoch::pin calls Handle::pin, which in turn calls pin on its Local. What happens during the execution of Local::pin? A lot:

    pub fn pin(&self) -> Guard {
        let guard = Guard { local: self };

        let guard_count = self.guard_count.get();
        self.guard_count.set(guard_count.checked_add(1).unwrap());

The Local guard count is increased, which is done amusingly by creating a Guard with self. If the guard count was previously zero:

        if guard_count == 0 {
            let global_epoch =          self.global().epoch.load(Ordering::Relaxed);
            let new_epoch = global_epoch.pinned();

This means that there are no other active participants in Local, and Local needs to query for the global epoch. The global epoch is loaded as the Local ...

Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.