Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a lock (wait) free doubly linked list possible?

Asking this question with C# tag, but if it is possible, it should be possible in any language.

Is it possible to implement a doubly linked list using Interlocked operations to provide no-wait locking? I would want to insert, add and remove, and clear without waiting.

like image 400
esac Avatar asked May 11 '09 19:05

esac


People also ask

What are the limitations of doubly linked list?

Disadvantages Of DLL:It uses extra memory when compared to the array and singly linked list. Since elements in memory are stored randomly, therefore the elements are accessed sequentially no direct access is allowed.

Is a doubly linked list FIFO or LIFO?

In doubly or two-way linked lists, two pointers are used in the structure, where one pointer points in the forward direction and the other points in the backward direction. These two pointers allow us to traverse a linked list in both ways, that is, in First in First Out (FIFO) order as well as LIFO order.

Can we call doubly linked list a Multilist?

Doubly linked list is a special case of multi-linked list.

Is doubly linked list the same as Deque?

A collection that has this property is called a double-ended queue, abbreviated “deque” and pronounced like “deck”. One way to implement a deque is a doubly-linked list, also known as a “head-tail linked list”.


1 Answers

Yes it's possible, here's my implementation of an STL-like Lock-Free Doubly-Linked List in C++.

Sample code that spawns threads to randomly perform ops on a list

It requires a 64-bit compare-and-swap to operate without ABA issues. This list is only possible because of a lock-free memory manager.

Check out the benchmarks on page 12. Performance of the list scales linearly with the number of threads as contention increases. The algorithm supports parallelism for disjoint accesses, so as the list size increases contention can decrease.

like image 160
Qarterd Avatar answered Sep 28 '22 07:09

Qarterd