Mono Class Library: System.Threading Namespace

System.Threading.Interlocked Class

The System.Threading.Interlocked class provides atomic operations for variables that are shared by multiple threads. [Edit]

See Also: Interlocked Members

public static class Interlocked

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

The System.Threading.Interlocked methods protect against errors that can occur when the scheduler switches contexts while a thread is updating a variable that can be accessed by other threads. The members of this class do not throw exceptions.

Note:

The Interlocked.Increment(Int32@) method and its counterpart, Interlocked.Decrement(Int32@), increment or decrement a variable and store the resulting value, as an atomic operation.

The Interlocked.Exchange(Int32@, int) method atomically exchanges the values of the specified variables. The Interlocked.CompareExchange(Int32@, int, int) method provides an atomic operation that compares two values and stores a third value in one of the variables, based on the outcome of the comparison.

[Edit]

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0