Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lock-Free Concurrent Linked List in Java

I would like to use a Linked List like the one described in this paper. However, I didn't find any Java implementation in the web.

If no java implementation of the above mentioned Linked List exists, I think, I would use the java.util.concurrent.ConcurrentLinkedQueue<E>. Is this a good choice (it is not really a linked list)?

If it's not a good choice, does anyone know of a reliable concurrent (thread-safe) wait-free(lock-free) Linked List implementation in Java?

like image 775
ptikobj Avatar asked Jan 18 '11 14:01

ptikobj


People also ask

What is lock free structure?

A data structure provides lock-freedom if, at any time, at least one thread can proceed. All other threads may be starving. The difference to obstruction-freedom is that there is at least one non-starving thread even if no threads are suspended.

What is lock free stack?

Stacks make for a simple case study, since the operations on stacks are very simple. The basic principle behind the implementation is that a thread will create a new version of the top of the stack and if no other thread has modified the stack, the change will be made public.

Is ConcurrentLinkedQueue thread-safe?

An unbounded thread-safe queue based on linked nodes. This queue orders elements FIFO (first-in-first-out). The head of the queue is that element that has been on the queue the longest time.

How lock free data structures work?

7.1. For a data structure to qualify as lock-free, more than one thread must be able to access the data structure concurrently. They don't have to be able to do the same operations; a lock-free queue might allow one thread to push and one to pop but break if two threads try to push new items at the same time.


1 Answers

ConcurrentLinkedQueue is a superb lock free queue and does what a concurrent single linked list can do. A small warning: if you dont use poll or peek and only iterator() (+.remove()) it will leak memory.

It's an outstanding Queue.

like image 54
bestsss Avatar answered Oct 07 '22 03:10

bestsss