-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
7
-
x86
-
windows_7
A DESCRIPTION OF THE REQUEST :
currently when using a Lock you need to use the try finally pattern (similar to streams):
Lock l = ...;
l.lock();
try {
// access the resource protected by this lock
} finally {
l.unlock();
}
with AutoCloseable this can be simplified with (names are debatable)
Lock l = ...;
try(AutoCloseable cl = l.lockWithClosable()){
// access the resource protected by this lock
}
JUSTIFICATION :
this makes using Locks closer in syntax and semantics to using the Object monitors
while still maintaining the full availability of the explicit lock and unlock methods
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the close of the returned AutoCloseable should call unlock() on the lock the first time and subsequent calls should either throw a IllegalMonitorStateException (similar to calling unlock on a ReentrantLock when not held) or be a no-op
this is to couple each close() of the AutoCloseable to a lockWithCloseable() as each unlock() is to a lock()
whether correct nesting should be enforced should be implementation defined
ACTUAL -
//not implemented
currently when using a Lock you need to use the try finally pattern (similar to streams):
Lock l = ...;
l.lock();
try {
// access the resource protected by this lock
} finally {
l.unlock();
}
with AutoCloseable this can be simplified with (names are debatable)
Lock l = ...;
try(AutoCloseable cl = l.lockWithClosable()){
// access the resource protected by this lock
}
JUSTIFICATION :
this makes using Locks closer in syntax and semantics to using the Object monitors
while still maintaining the full availability of the explicit lock and unlock methods
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the close of the returned AutoCloseable should call unlock() on the lock the first time and subsequent calls should either throw a IllegalMonitorStateException (similar to calling unlock on a ReentrantLock when not held) or be a no-op
this is to couple each close() of the AutoCloseable to a lockWithCloseable() as each unlock() is to a lock()
whether correct nesting should be enforced should be implementation defined
ACTUAL -
//not implemented