I have defined a simple bank class which is attached to this issue.
Basically it's a bank with a map of ids (ints) to accounts (instances of the class Account) and a lock (RentrantReadWriteLock) to control the access to this map. The class Account has a balance (int) and a lock (ReentrantLock) to protect the balance from concurrent accesses. Thus, we have concurrency control for:
In the class defined there's a problem with the method transfer: in certain situations it can lead to a deadlock. This happens because the locks for the accounts are not obtained in order:
cfrom = accounts.get(from); cto = accounts.get(to);
For instance, if there's a transfer from account0 to account1 in thread1 at the same time as a transfer from account1 to account0 in thread2, the following thread interleaving leads to a deadlock:
I have been trying to catch this deadlock with jpf and it does not report it. I have been using the default jpf.properties, the only change I made was remove the gov.nasa.jpf.vm.NoUncaughtExceptionsProperty from search.properties. The application properties is as simple as:
target = BankReadWriteLock
classpath=.
I have tried to add to the application properties the gov.nasa.jpf.listener.DeadlockAnalyzer listener but it didn't work either.
This is the output I receive:
I find it to be very strange the fact that it only reports one new state. It seems like different thread interleavings are not being considered.
Is there a problem with the configuration I am using or jpf is really not catching this deadlock?