I am trying to design a linked list in c++ that allows concurrent access. Clearly using a single lock for this list is grossly inefficient since disjoint areas may be updated in parallel. Now what are my options other than storing a lock per node?
Also, would a non-blocking version be a better bet in this case? Any relevant links, anyone?
EDIT: Thanks for the responses people. Couple of things I'd like to add:
It is used to implement Queue with the help of LinkedList concurrently. It is an unbounded thread-safe implementation of Queue which inserts elements at the tail of the Queue in a FIFO(first-in-first-out) fashion. It can be used when an unbounded Queue is shared among many threads.
A singly-linked list may be LIFO (last-in-first-out) or FIFO (first-in-first-out). If the list is using the LIFO method, the nodes will be added to and deleted from the same end. If it's using FIFO, nodes will be added to one end and deleted from the opposite end. Additionally, the linked list may be sorted.
ConcurrentLinkedQueue is an unbounded thread-safe queue which arranges the element in FIFO. New elements are added at the tail of this queue and the elements are added from the head of this queue. ConcurrentLinkedQueue class and its iterator implements all the optional methods of the Queue and Iterator interfaces.
Just like a garland is made with flowers, a linked list is made up of nodes. We call every flower on this particular garland to be a node. And each of the node points to the next node in this list as well as it has data (here it is type of flower).
Linked lists are inherently sequential data structures. No matter what kind of machinery you use to implement it, the interface and expected behavior imply sequential logic.
What are you trying to do? That should determine what data structure you use, not the familiarity of the data structures you already are comfortable with.
It's possible to implement a non-blocking singly linked list using interlocked functions:
Interlocked Singly Linked Lists
I don't think it's possible to implement a non-blocking doubly linked list without interlocked compare-and-swap (CAS), which isn't widely available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With