Janaka
Janaka

Reputation: 471

How to handle reentrancy with StampLocks

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.

Upvotes: 1

Views: 81

Answers (0)

Related Questions