0

The use case requires me not to block any thread while retrieving or putting values into a List<V>. I have been looking at compare-and-swap algorithms that require you to implement a datastructure yourself. I would like to use an existing implementation of Collection such as an ArrayList or LinkedList and achieve a lock-free insertion and look up of elements. There is an option to have AtomicReferenceArray<E>. But I was wondering if there was a way to achieve this for a variable-sized list.

17
  • 5
    There is the ConcurrentLinkedQueue which is lock free. If you want the full functionality of a List then you will need to look at external libraries. Commented Feb 17, 2015 at 12:22
  • List<String> sinchronizedList = Collections.sinchronizedList(yourList); Commented Feb 17, 2015 at 12:24
  • 1
    @bigdestroyer: The OP wants to avoid synchronized datastructures. Synchronized is simply not lock-free. Commented Feb 17, 2015 at 12:25
  • 2
    @bigdestroyer: no, lock-free means that there are no locks. The algorithms can run in parallel and perform a compare-and-swap in the end, a hardware-based atomic instruction to reduce the overhead. Commented Feb 17, 2015 at 12:30
  • 1
    @Zhedar: see this. Commented Feb 17, 2015 at 12:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.