A project made for the Concurrent Programming course during the winter semester of the 2021/22 academic year. Implemented in Java.
The task was to create a Cube class, representing a concurrent Rubik's Cube of given size, which supplies three methods:
- Its constructor
Cube(int size, BiConsumer<Integer,Integer> beforeRotation, BiConsumer<Integer,Integer> afterRotation, Runnable beforeShowing, Runnable afterShowing)
, which constructs a Rubik's Cube of dimensionssize
xsize
xsize
, the operations on which are to be performed concurrently if possible. - The rotate method
void rotate(int side, int layer)
which rotates thelayer
-th layer as looking from theside
-th side, indexing from 0, that isside
belongs to the range [0,5] andlayer
belongs to the range [0,size
-1]. - The show method
String show()
which creates a String object with a text representation of the Cube.
The rotate method should have also called beforeRotation(side, layer)
directly before performing the actual rotation and afterRotation(side, layer)
directly after performing the rotation. Similarly, the show method had to call beforeShowing()
and afterShowing
directly before and after reading the state of the Cube. There were no further assumptions which could be made about these four functions, apart from that they would halt.
The Cube had to support concurrent operations, which meant that if two threads could perform an operation at the same time, then they should have performed it at the same time if there were no contraindications, like the existence of other waiting processes. No two threads should have been performing a rotate and a show operation at the same time and no two threads should have been performing a rotation, which shared a block of the Rubik's Cube. There were no other safety requirements. Interrupts also had to be taken into account and an interrupted thread had to give up performing the planned operation if it was interrupted before clearing the entry protocols. An interrupted thread could not compromise the integrity of the protocols or the Cube.
The only requirement regarding the order of operations performed on the cube is that the result of the show method had to be correct for at least one possible order of performing the rotate and show methods.
The concurrentcube package was also required to contain JUnit 5 tests testing the Cube class thoroughly, including its correctness, concurrent safety and concurrent liveness and how it reacted to interrupts.
No documentation was required. But I provided one anyway. Except for the tests.