This page is located in archive.

Non-blocking Algorithms

Your task is to implement a concurrent add-only hash-set of Strings without using locks.

  1. Download the program from git repository: git clone https://gitlab.fel.cvut.cz/cuchymar/nonblock-map
  2. See the naive synchronized implementation in SynchronizedDictionary class.
  3. Implement the same behavior in NonblockDictionary class without locks by using atomic operations (see java.util.concurrent.atomic package).
    • Which atomic structure is useful as implementation of bins?
    • If an atomic object (Atomic* classes) is created too many times, use Atomic*FieldUpdater instead to avoid unnecessary memory overhead.
  4. Test your implementation with provided tests and try to implement your own (especially the concurrent ones):
    • Single-thread JUnit tests
    • Basic test is done also in the Main class
    • Concurrent tests using two frameworks (basic instructions are in the test implementations, detailed on their websites):
      • jcstress - JcstressDictionaryTest in the main source folder
      • vmlens - VmlensDictionaryTest in the test source folder
  5. Upload your solution to BRUTE
    • Upload only your .java files you modified (or pom.xml if you changed it).
    • Do NOT upload any binaries or libraries.
    • There is no automatic evaluation and the code will be evaluated manually. You will present the code to the tutor and explain what key parts of the code do.

Concurrent Testing

There is several available tools that can be used:

  • vmlens - examples provided in the template of the assignment and also on the website of the tool
  • jcstress - OpenJDK tool with code samples provided
  • Java Pathfinder - Tool developed by NASA for model checking of java bytecode programs.

Voluntary Exercises

You can also try to implement the two following assignments from the previous year.


Some related slides are available in here

  1. Start with the implementation of the set using simple linked list.
  2. Implement the set with AtomicMarkableReference<Type> holding reference to the next node and the mark if this node holding the reference is logically deleted
    1. Implement a helper method find(int value), which traverses the list until it finds the correct position of the value and deletes the marked nodes during the traversal.
    2. Implement the delete(int value) method with marking of the deleted node beforehand (logical deletion) and with other threads helping with the physical deletion if they find any marked node.
    3. Implement add(int value) method.
  3. Implement wait-free contains(int value) method. The method is read-only.


  1. Generalize the previous algorithm to a skip list. Use the template from https://gitlab.fel.cvut.cz/cuchymar/nonblock-skiplist-template.git
    1. To clarify how the skip list works, we recommend to start with the contains method which just goes through the list and tries to find the value (without calling find method). It does not need to change anything in the skip list. This point is not mandatory.
    2. Try to generalize the method find(), to look not only for one predecessor and one successor of the searched value but for the predecessors on all the levels.
    3. Implement add and delete methods
    4. Testing is an important part of implementation of any algorithm therefore your task is also to create tests. Unfortunatelly, testing of concurrent structures is difficult.
      • Start with testing of only single-thread behaviour (very easy - e.g. classical JUnit).
      • Try to desing some tests that checks the functionality in a multi-threaded environment.
      • You have to be able to demonstrate that the algorithm is working correctly.
courses/b4m36esw/labs/lab05.txt · Last modified: 2021/03/22 13:54 by cuchymar