Skip to content

Commit 6b476bb

Browse files
committed
LockFreeLinkedSet: add some comments on algorithm
1 parent f8dd2b2 commit 6b476bb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/concurrent/edge/lock_free_linked_set.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33

44
module Concurrent
55
module Edge
6+
# This class implements a lock-free linked set. The general idea of this
7+
# implementation is this: each node has a successor which is an Atomic
8+
# Markable Reference. This is used to ensure that all modifications to the
9+
# list are atomic, preserving the structure of the linked list under _any_
10+
# circumstance in a multithreaded application.
11+
#
12+
# One interesting aspect of this algorithm occurs with removing a node.
13+
# Instead of physically removing a node when remove is called, a node is
14+
# logically removed, by 'marking it.' By doing this, we prevent calls to
15+
# `remove` from traversing the list twice to perform a physical removal.
16+
# Instead, we have have calls to `add` and `remove` clean up all marked
17+
# nodes they encounter while traversing the list.
18+
#
19+
# This algorithm is a variation of the Nonblocking Linked Set found in
20+
# 'The Art of Multiprocessor Programming' by Herlihy and Shavit.
621
class LockFreeLinkedSet
722
include Enumerable
823

0 commit comments

Comments
 (0)