In this example:
private ReentrantReadWriteLock mLock = new ReentrantReadWriteLock();
public void method(boolean condition) {
try {
mLock.writelock.lock()
if (condition) {
mLock.writelock.unlock();
}
} finally {
mLock.writelock.unlock();
}
}
What happens when mLock.writelock.unlock()
is called in the finally
block if the unlock in the if
statement has been executed?
Is this code safe or do I need to perform some check on whether there is a lock in place before attempting to unlock?