Provides a mutual exclusion lock primitive where a thread trying to acquire the lock waits in a loop repeatedly checking until the lock becomes available.
More...
|
| SpinLock (bool enableThreadOwnerTracking) |
| Initializes a new instance of the T:System.Threading.SpinLock structure with the option to track thread IDs to improve debugging. More...
|
|
void | Enter (ref bool lockTaken) |
| Acquires the lock in a reliable manner, such that even if an exception occurs within the method call, lockTaken can be examined reliably to determine whether the lock was acquired. More...
|
|
void | TryEnter (ref bool lockTaken) |
| Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lockTaken can be examined reliably to determine whether the lock was acquired. More...
|
|
void | TryEnter (TimeSpan timeout, ref bool lockTaken) |
| Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lockTaken can be examined reliably to determine whether the lock was acquired. More...
|
|
void | TryEnter (int millisecondsTimeout, ref bool lockTaken) |
| Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lockTaken can be examined reliably to determine whether the lock was acquired. More...
|
|
void | Exit () |
| Releases the lock. More...
|
|
void | Exit (bool useMemoryBarrier) |
| Releases the lock. More...
|
|
Provides a mutual exclusion lock primitive where a thread trying to acquire the lock waits in a loop repeatedly checking until the lock becomes available.
Definition at line 14 of file SpinLock.cs.
◆ SpinLock()
System.Threading.SpinLock.SpinLock |
( |
bool |
enableThreadOwnerTracking | ) |
|
Initializes a new instance of the T:System.Threading.SpinLock structure with the option to track thread IDs to improve debugging.
- Parameters
-
enableThreadOwnerTracking | Whether to capture and use thread IDs for debugging purposes. |
Definition at line 128 of file SpinLock.cs.
◆ Enter()
void System.Threading.SpinLock.Enter |
( |
ref bool |
lockTaken | ) |
|
Acquires the lock in a reliable manner, such that even if an exception occurs within the method call, lockTaken can be examined reliably to determine whether the lock was acquired.
- Parameters
-
lockTaken | True if the lock is acquired; otherwise, false. lockTaken must be initialized to false prior to calling this method. |
- Exceptions
-
T:System.ArgumentException | The lockTaken argument must be initialized to false prior to calling Enter. |
T:System.Threading.LockRecursionException | Thread ownership tracking is enabled, and the current thread has already acquired this lock. |
Definition at line 142 of file SpinLock.cs.
◆ Exit() [1/2]
void System.Threading.SpinLock.Exit |
( |
| ) |
|
Releases the lock.
- Exceptions
-
T:System.Threading.SynchronizationLockException | Thread ownership tracking is enabled, and the current thread is not the owner of this lock. |
Definition at line 362 of file SpinLock.cs.
◆ Exit() [2/2]
void System.Threading.SpinLock.Exit |
( |
bool |
useMemoryBarrier | ) |
|
Releases the lock.
- Parameters
-
useMemoryBarrier | A Boolean value that indicates whether a memory fence should be issued in order to immediately publish the exit operation to other threads. |
- Exceptions
-
T:System.Threading.SynchronizationLockException | Thread ownership tracking is enabled, and the current thread is not the owner of this lock. |
Definition at line 380 of file SpinLock.cs.
◆ TryEnter() [1/3]
void System.Threading.SpinLock.TryEnter |
( |
ref bool |
lockTaken | ) |
|
Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lockTaken can be examined reliably to determine whether the lock was acquired.
- Parameters
-
lockTaken | True if the lock is acquired; otherwise, false. lockTaken must be initialized to false prior to calling this method. |
- Exceptions
-
T:System.ArgumentException | The lockTaken argument must be initialized to false prior to calling TryEnter. |
T:System.Threading.LockRecursionException | Thread ownership tracking is enabled, and the current thread has already acquired this lock. |
Definition at line 157 of file SpinLock.cs.
◆ TryEnter() [2/3]
void System.Threading.SpinLock.TryEnter |
( |
TimeSpan |
timeout, |
|
|
ref bool |
lockTaken |
|
) |
| |
Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lockTaken can be examined reliably to determine whether the lock was acquired.
- Parameters
-
timeout | A T:System.TimeSpan that represents the number of milliseconds to wait, or a T:System.TimeSpan that represents -1 milliseconds to wait indefinitely. |
lockTaken | True if the lock is acquired; otherwise, false. lockTaken must be initialized to false prior to calling this method. |
- Exceptions
-
T:System.ArgumentOutOfRangeException | timeout is a negative number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater than F:System.Int32.MaxValue milliseconds. |
T:System.ArgumentException | The lockTaken argument must be initialized to false prior to calling TryEnter. |
T:System.Threading.LockRecursionException | Thread ownership tracking is enabled, and the current thread has already acquired this lock. |
Definition at line 170 of file SpinLock.cs.
◆ TryEnter() [3/3]
void System.Threading.SpinLock.TryEnter |
( |
int |
millisecondsTimeout, |
|
|
ref bool |
lockTaken |
|
) |
| |
Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lockTaken can be examined reliably to determine whether the lock was acquired.
- Parameters
-
millisecondsTimeout | The number of milliseconds to wait, or F:System.Threading.Timeout.Infinite (-1) to wait indefinitely. |
lockTaken | True if the lock is acquired; otherwise, false. lockTaken must be initialized to false prior to calling this method. |
- Exceptions
-
T:System.ArgumentOutOfRangeException | millisecondsTimeout is a negative number other than -1, which represents an infinite time-out. |
T:System.ArgumentException | The lockTaken argument must be initialized to false prior to calling TryEnter. |
T:System.Threading.LockRecursionException | Thread ownership tracking is enabled, and the current thread has already acquired this lock. |
Definition at line 188 of file SpinLock.cs.
◆ IsHeld
bool System.Threading.SpinLock.IsHeld |
|
get |
Gets whether the lock is currently held by any thread.
- Returns
- true if the lock is currently held by any thread; otherwise false.
Definition at line 81 of file SpinLock.cs.
◆ IsHeldByCurrentThread
bool System.Threading.SpinLock.IsHeldByCurrentThread |
|
get |
Gets whether the lock is held by the current thread.
- Returns
- true if the lock is held by the current thread; otherwise false.
- Exceptions
-
T:System.InvalidOperationException | Thread ownership tracking is disabled. |
Definition at line 99 of file SpinLock.cs.
◆ IsThreadOwnerTrackingEnabled
bool System.Threading.SpinLock.IsThreadOwnerTrackingEnabled |
|
get |
Gets whether thread ownership tracking is enabled for this instance.
- Returns
- true if thread ownership tracking is enabled for this instance; otherwise false.
Definition at line 116 of file SpinLock.cs.
The documentation for this struct was generated from the following file: