Share via


ILock.LockInterruptibly Method

Definition

Acquires the lock unless the current thread is Thread#interrupt interrupted.

[Android.Runtime.Register("lockInterruptibly", "()V", "GetLockInterruptiblyHandler:Java.Util.Concurrent.Locks.ILockInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public void LockInterruptibly ();
[<Android.Runtime.Register("lockInterruptibly", "()V", "GetLockInterruptiblyHandler:Java.Util.Concurrent.Locks.ILockInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member LockInterruptibly : unit -> unit
Attributes

Exceptions

if the current thread is interrupted while acquiring the lock (and interruption of lock acquisition is supported)

Remarks

Acquires the lock unless the current thread is Thread#interrupt interrupted.

Acquires the lock if it is available and returns immediately.

If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

<ul> <li>The lock is acquired by the current thread; or <li>Some other thread Thread#interrupt interrupts the current thread, and interruption of lock acquisition is supported. </ul>

If the current thread: <ul> <li>has its interrupted status set on entry to this method; or <li>is Thread#interrupt interrupted while acquiring the lock, and interruption of lock acquisition is supported, </ul> then InterruptedException is thrown and the current thread's interrupted status is cleared.

<b>Implementation Considerations</b>

The ability to interrupt a lock acquisition in some implementations may not be possible, and if possible may be an expensive operation. The programmer should be aware that this may be the case. An implementation should document when this is the case.

An implementation can favor responding to an interrupt over normal method return.

A Lock implementation may be able to detect erroneous use of the lock, such as an invocation that would cause deadlock, and may throw an (unchecked) exception in such circumstances. The circumstances and the exception type must be documented by that Lock implementation.

Java documentation for java.util.concurrent.locks.Lock.lockInterruptibly().

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.

Applies to