I am converting a code with reentrant locks into stamp locks. The code consists of a scenario where readlock is inside the writelock as following example.
private final ReadWriteLock lock = new ReentrantReadWriteLock();
A() {
lock.writeLock().lock();
...
B();
...
}
B () {
lock.readLock().lock();
...
}
The stamp locks are not reentrant. Then if I change readLock() into tryOptimisticRead() and writeLock() with writeLock() in stamp locks, there may be a deadlock scenario.
Hence, I want to know how to handle this kind of scenarios with stamp locks.