ReentrantLock.IsHeldByCurrentThread Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Queries if this lock is held by the current thread.
public virtual bool IsHeldByCurrentThread { [Android.Runtime.Register("isHeldByCurrentThread", "()Z", "GetIsHeldByCurrentThreadHandler")] get; }
[<get: Android.Runtime.Register("isHeldByCurrentThread", "()Z", "GetIsHeldByCurrentThreadHandler")>]
member this.IsHeldByCurrentThread : bool
Property Value
true
if current thread holds this lock and
false
otherwise
- Attributes
Remarks
Queries if this lock is held by the current thread.
Analogous to the Thread#holdsLock(Object)
method for built-in monitor locks, this method is typically used for debugging and testing. For example, a method that should only be called while a lock is held can assert that this is the case:
{@code
class X {
final ReentrantLock lock = new ReentrantLock();
// ...
public void m() {
assert lock.isHeldByCurrentThread();
// ... method body
}
}}
It can also be used to ensure that a reentrant lock is used in a non-reentrant manner, for example:
{@code
class X {
final ReentrantLock lock = new ReentrantLock();
// ...
public void m() {
assert !lock.isHeldByCurrentThread();
lock.lock();
try {
// ... method body
} finally {
lock.unlock();
}
}
}}
Java documentation for java.util.concurrent.locks.ReentrantLock.isHeldByCurrentThread()
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.