Class Blocking
Blocking provides a set of helper methods related to blocking a thread.
Inherited Members
Namespace: Tangosol.Util
Assembly: Coherence.dll
Syntax
public class Blocking
Methods
Enter(object)
Acquires an exclusive lock on the specified object while still respecting the calling thread's ThreadTimeout.
Declaration
public static void Enter(object o)
Parameters
Type | Name | Description |
---|---|---|
object | o | The object on which to acquire the monitor lock. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted or the timeout is reached. |
Enter(object, ref bool)
Acquires an exclusive lock on the specified object while still respecting the calling thread's ThreadTimeout, and atomically sets a value that indicates whether the lock was taken.
Declaration
public static void Enter(object o, ref bool lockTaken)
Parameters
Type | Name | Description |
---|---|---|
object | o | The object on which to acquire the monitor lock. |
bool | lockTaken | The result of the attempt to acquire the lock, passed by reference. The input must be false. The output is true if the lock is acquired; otherwise, the output is false. The output is set even if an exception occurs during the attempt to acquire the lock. Note: If no exception occurs, the output of this method is always true. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted or the timeout is reached. |
EnterReadLock(ReaderWriterLockSlim)
Tries to enter the lock in read mode while still respecting the calling thread's ThreadTimeout.
Declaration
public static void EnterReadLock(ReaderWriterLockSlim rwLock)
Parameters
Type | Name | Description |
---|---|---|
ReaderWriterLockSlim | rwLock | The lock. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted or the timeout is reached. |
EnterUpgradeableReadLock(ReaderWriterLockSlim)
Tries to enter the lock in upgradeable mode while still respecting the calling thread's ThreadTimeout.
Declaration
public static void EnterUpgradeableReadLock(ReaderWriterLockSlim rwLock)
Parameters
Type | Name | Description |
---|---|---|
ReaderWriterLockSlim | rwLock | The lock. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted or the timeout is reached. |
EnterWriteLock(ReaderWriterLockSlim)
Tries to enter the lock in write mode while still respecting the calling thread's ThreadTimeout.
Declaration
public static void EnterWriteLock(ReaderWriterLockSlim rwLock)
Parameters
Type | Name | Description |
---|---|---|
ReaderWriterLockSlim | rwLock | The lock. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted or the timeout is reached. |
Sleep(int)
Invoke Sleep(int) while still respecting the calling thread's ThreadTimeout.
Declaration
public static void Sleep(int millis)
Parameters
Type | Name | Description |
---|---|---|
int | millis | The maximum number of milliseconds to sleep. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted. |
Sleep(TimeSpan)
Invoke Sleep(TimeSpan) while still respecting the calling thread's ThreadTimeout.
Declaration
public static void Sleep(TimeSpan span)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | span | The maximum TimeSpan to sleep. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted. |
TryEnter(object, int)
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object while still respecting the calling thread's ThreadTimeout
Declaration
public static bool TryEnter(object obj, int millis)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object on which to acquire the lock. |
int | millis | The maximum number of milliseconds to wait for the lock. |
Returns
Type | Description |
---|---|
bool | true if the current thread acquires the lock; otherwise, false. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted. |
TryEnter(object, int, ref bool)
Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object, while still respecting the calling thread's ThreadTimeout, and atomically sets a value that indicates whether the lock was taken.
Declaration
public static void TryEnter(object obj, int millis, ref bool lockTaken)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object on which to acquire the lock. |
int | millis | The maximum number of milliseconds to wait for the lock. |
bool | lockTaken | The result of the attempt to acquire the lock, passed by reference. The input must be false. The output is true if the lock is acquired; otherwise, the output is false. The output is set even if an exception occurs during the attempt to acquire the lock. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted. |
TryEnter(object, TimeSpan)
Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object while still respecting the calling thread's ThreadTimeout
Declaration
public static bool TryEnter(object obj, TimeSpan span)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object on which to acquire the lock. |
TimeSpan | span | The maximum time to wait for the lock. |
Returns
Type | Description |
---|---|
bool | true if the current thread acquires the lock; otherwise, false. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted. |
TryEnter(object, TimeSpan, ref bool)
Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object, while still respecting the calling thread's ThreadTimeout, and atomically sets a value that indicates whether the lock was taken.
Declaration
public static void TryEnter(object obj, TimeSpan span, ref bool lockTaken)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object on which to acquire the lock. |
TimeSpan | span | The maximum time to wait for the lock. |
bool | lockTaken | The result of the attempt to acquire the lock, passed by reference. The input must be false. The output is true if the lock is acquired; otherwise, the output is false. The output is set even if an exception occurs during the attempt to acquire the lock. |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted. |
TryEnterReadLock(ReaderWriterLockSlim, int)
Tries to enter the lock in read mode, with an optional time-out while still respecting the calling thread's ThreadTimeout.
Declaration
public static bool TryEnterReadLock(ReaderWriterLockSlim rwLock, int millis)
Parameters
Type | Name | Description |
---|---|---|
ReaderWriterLockSlim | rwLock | The lock. |
int | millis | The maximum interval to wait, or -1 milliseconds to wait indefinitely. |
Returns
Type | Description |
---|---|
bool | true if the calling thread entered read mode, otherwise, false. |
TryEnterReadLock(ReaderWriterLockSlim, TimeSpan)
Tries to enter the lock in read mode, with an optional time-out while still respecting the calling thread's ThreadTimeout.
Declaration
public static bool TryEnterReadLock(ReaderWriterLockSlim rwLock, TimeSpan span)
Parameters
Type | Name | Description |
---|---|---|
ReaderWriterLockSlim | rwLock | The lock. |
TimeSpan | span | The maximum interval to wait, or -1 milliseconds to wait indefinitely. |
Returns
Type | Description |
---|---|
bool | true if the calling thread entered read mode, otherwise, false. |
TryEnterUpgradeableReadLock(ReaderWriterLockSlim, int)
Tries to enter the lock in upgradeable mode, with an optional time-out while still respecting the calling thread's ThreadTimeout.
Declaration
public static bool TryEnterUpgradeableReadLock(ReaderWriterLockSlim rwLock, int millis)
Parameters
Type | Name | Description |
---|---|---|
ReaderWriterLockSlim | rwLock | The lock. |
int | millis | The maximum interval to wait, or -1 milliseconds to wait indefinitely. |
Returns
Type | Description |
---|---|
bool | true if the calling thread entered upgradeable mode, otherwise, false. |
TryEnterUpgradeableReadLock(ReaderWriterLockSlim, TimeSpan)
Tries to enter the lock in upgradeable mode, with an optional time-out while still respecting the calling thread's ThreadTimeout.
Declaration
public static bool TryEnterUpgradeableReadLock(ReaderWriterLockSlim rwLock, TimeSpan span)
Parameters
Type | Name | Description |
---|---|---|
ReaderWriterLockSlim | rwLock | The lock. |
TimeSpan | span | The maximum interval to wait, or -1 milliseconds to wait indefinitely. |
Returns
Type | Description |
---|---|
bool | true if the calling thread entered upgradeable mode, otherwise, false. |
TryEnterWriteLock(ReaderWriterLockSlim, int)
Tries to enter the lock in write mode, with an optional time-out while still respecting the calling thread's ThreadTimeout.
Declaration
public static bool TryEnterWriteLock(ReaderWriterLockSlim rwLock, int millis)
Parameters
Type | Name | Description |
---|---|---|
ReaderWriterLockSlim | rwLock | The lock. |
int | millis | The maximum interval to wait, or -1 milliseconds to wait indefinitely. |
Returns
Type | Description |
---|---|
bool | true if the calling thread entered write mode, otherwise, false. |
TryEnterWriteLock(ReaderWriterLockSlim, TimeSpan)
Tries to enter the lock in write mode, with an optional time-out while still respecting the calling thread's ThreadTimeout.
Declaration
public static bool TryEnterWriteLock(ReaderWriterLockSlim rwLock, TimeSpan span)
Parameters
Type | Name | Description |
---|---|---|
ReaderWriterLockSlim | rwLock | The lock. |
TimeSpan | span | The maximum interval to wait, or -1 milliseconds to wait indefinitely. |
Returns
Type | Description |
---|---|
bool | true if the calling thread entered write mode, otherwise, false. |
Wait(object)
Wait on the the specified monitor while still respecting the calling thread's ThreadTimeout.
Declaration
public static bool Wait(object monitor)
Parameters
Type | Name | Description |
---|---|---|
object | monitor | The monitor to wait on |
Returns
Type | Description |
---|---|
bool |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted or the timeout is reached. |
Wait(object, int)
Wait on the the specified monitor while still respecting the calling thread's ThreadTimeout.
Declaration
public static bool Wait(object monitor, int millis)
Parameters
Type | Name | Description |
---|---|---|
object | monitor | The monitor to wait on. |
int | millis | The maximum number of milliseconds to wait. |
Returns
Type | Description |
---|---|
bool |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted. |
Wait(object, TimeSpan)
Wait on the specified monitor while still respecting the calling thread's ThreadTimeout.
Declaration
public static bool Wait(object monitor, TimeSpan span)
Parameters
Type | Name | Description |
---|---|---|
object | monitor | The monitor to wait on. |
TimeSpan | span | The maximum TimeSpan to wait. |
Returns
Type | Description |
---|---|
bool |
Exceptions
Type | Condition |
---|---|
ThreadInterruptedException | If the thread is interrupted. |