This project has been developed for the course of Concurrent and Distributed Systems, Master of Engineering in Embedded Computing Systems (University of Pisa and Sant'Anna School of Advanced Studies).
Implement a synchronization mechanism similar to the mechanism provided by Java within the java.util.concurrent package (explicit Lock and Condition variables) but whose behaviour is in accordance with the semantic "signal-and-urgent".
For the implementation of this mechanism you can use only the built-in synchronization constructs provided by Java (i.e. synchronized blocks or synchronized methods ) and the methods wait(), notify() and notifyAll() provided by the class Object).
In particular:
- implement the class
FairLockthat provides the two methodslock()andunlock(), to be used to explicitly guarantee the mutual exclusion of critical sections. Your implementation must guarantee that threads waiting to acquire aFairLockare awakened in a FIFO order - implement also the class
Conditionthat provides the two methodsawait()andsignal()that are used, respectively, to block a thread on aConditionvariable and to awake the first thread (if any) blocked on theConditionvariable. In other wordsConditionvariables must be implemented as FIFO queues. The semantics of the signal operation must be "signal-and-urgent". Remember that every instance of the classConditionmust be intrinsically bound to a lock (instance of the classFairLock). For this reason, the classFairLockprovides, in addition to methodslock()andunlock(), also the methodnewCondition()that returns a newConditioninstance that is bound to thisFairLockinstance.
As a simple example of the use of the previous mechanism, implement a manager of a single resource that dynamically allocates the resource to three client threads: ClientA1, ClientA2 and ClientB. If the resource is in use by ClientA1 or by ClientA2, when it is released and both ClientB and the other ClientA are waiting for the resource, ClientB must be privileged.
Provide also the implementation of the same manager but now by using the analogous mechanism provided by Java (Lock and Condition variables whose behaviour is in accordance with the semantics “signal-and-continue” and point out the differences, if any, between this implementation and the previous one.
By using the language FSP, provide the design model of the problem described at point 2.0.
From the design model described at point 3.0, derive the corresponding Java program implemented by using the Lock and Condition variables provided by Java and whose behaviour is in accordance with the semantics “signal-and-continue”.
By modeling this implementation with the FSP language, verify that it satisfies the problem’s specification.
The tools used for the project were
- Java JDK 8u111 for implementing and testing
- LTS Analyzer for analysis using the FSP language
The project folder resembles the following structure:
/assignment1:/locks: Java files forFairLockimplementation/test: Java files for testing
/assignment2:/clients: Java files for clients implementation/managers: Java files for managers implementation/test: Java files for testing
/assignment3:/implementation: Java files for manager implementation/models: LTSA models/test: Java files for testing
The design workflow can be found in the report file.
This project is licensed under the MIT License - see the LICENSE file for details