From bbd6112bf2ae0f77dd45ce68988ae6fd975074c0 Mon Sep 17 00:00:00 2001 From: Janggun Lee Date: Thu, 29 Aug 2024 22:27:07 +0900 Subject: [PATCH] Add some commments --- src/lockfree/list.rs | 3 +++ src/lockfree/queue.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/lockfree/list.rs b/src/lockfree/list.rs index 1cff45c1128..812b98eb070 100644 --- a/src/lockfree/list.rs +++ b/src/lockfree/list.rs @@ -7,6 +7,9 @@ use core::sync::atomic::Ordering::*; use crossbeam_epoch::{Atomic, Guard, Owned, Shared}; /// Linked list node. +// TODO: This node type is very brittle; what if some list creates a node, and uses it to add it to +// another, separate list? Also see the discussions at . +// The public API surface is way too large. #[derive(Debug)] pub struct Node { /// Mark: tag(), Tag: not needed diff --git a/src/lockfree/queue.rs b/src/lockfree/queue.rs index 39632ed1dbb..e6060cf3955 100644 --- a/src/lockfree/queue.rs +++ b/src/lockfree/queue.rs @@ -121,6 +121,11 @@ impl Queue { .compare_exchange(tail, next, Release, Relaxed, guard); } + // After the above load & CAS, the thread view ensures that the index of tail is greater + // than that of current head. We relase that view to the head with the below CAS, + // ensuring that the index of the new head is less than or equal to that of the tail. + // + // Note: similar reasoning is done in SC memory regarding index of head and tail. if self .head .compare_exchange(head, next, Release, Relaxed, guard)