mscorlib 4.0.0.0 System.ValueType System.Diagnostics.DebuggerDisplay("IsHeld = {IsHeld}") System.Diagnostics.DebuggerTypeProxy("System.Threading.SpinLock+SystemThreading_SpinLockDebugView")

For an example of how to use a Spin Lock, see How to: Use SpinWait and SpinLock.

Spin locks can be used for leaf-level locks where the object allocation implied by using a , in size or due to garbage collection pressure, is overly expensive. A spin lock can be useful in to avoid blocking; however, if you expect a significant amount of blocking, you should probably not use spin locks due to excessive spinning. Spinning can be beneficial when locks are fine-grained and large in number (for example, a lock per node in a linked list) and also when lock hold-times are always extremely short. In general, while holding a spin lock, one should avoid any of these actions:

blocking,

calling anything that itself may block,

holding more than one spin lock at once,

making dynamically dispatched calls (interface and virtuals),

making statically dispatched calls into any code one doesn't own, or

allocating memory.

should only be used after you have been determined that doing so will improve an application's performance. It is also important to note that is a value type, for performance reasons. For this reason, you must be very careful not to accidentally copy a instance, as the two instances (the original and the copy) would then be completely independent of one another, which would likely lead to erroneous behavior of the application. If a instance must be passed around, it should be passed by reference rather than by value.

Do not store instances in readonly fields.

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.

- Constructor
  4.0.0.0

  The default constructor for tracks thread ownership.

  Initializes a new instance of the structure with the option to track thread IDs to improve debugging.

  Whether to capture and use thread IDs for debugging purposes.
- Method
  4.0.0.0
  System.Void `` To be added. To be added. To be added.
- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void

  The default overload of provides the same behavior as if calling using true as the argument.

  If you call without having first called the internal state of the can become corrupted.

  Releases the lock.

- Method
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void ``

  Calling with the argument set to true will improve the fairness of the lock at the expense of some performance. The default overload behaves as if specifying true for .

  If you call without having first called the internal state of the can become corrupted.

  Releases the lock.

  A Boolean value that indicates whether a memory fence should be issued in order to immediately publish the exit operation to other threads.
- Property
  4.0.0.0
  System.Boolean To be added. To be added.

  Gets whether the lock is currently held by any thread.

- Property
  4.0.0.0
  System.Boolean To be added.

  If the lock was initialized to track owner threads, this will return whether the lock is acquired by the current thread. It is invalid to use this property when the lock was initialized to not track thread ownership.

  Gets whether the lock is held by the current thread.

- Property
  4.0.0.0
  System.Boolean To be added. To be added.

  Gets whether thread ownership tracking is enabled for this instance.

- Method
  4.0.0.0
  System.Void `` To be added. To be added. To be added.
- Method
  4.0.0.0
  System.Void `` `` To be added. To be added. To be added. To be added.
- Method
  4.0.0.0
  System.Void `` `` To be added. To be added. To be added. To be added.