Class Interlocked
Provides atomic operations for variables that are shared by multiple threads.
public static class Interlocked
- Inheritance
-
Interlocked
- Inherited Members
Methods
CompareExchange(ref int, int, int)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
public static int CompareExchange(ref int location1, int value, int comparand)
Parameters
location1
intThe destination, whose value is compared with comparand and possibly replaced.
value
intThe value that replaces the destination value if the comparison results in equality.
comparand
intThe value that is compared to the value at location1.
Returns
- int
The original value in location1.
Decrement(ref int)
Decrements a specified variable and stores the result, as an atomic operation.
public static int Decrement(ref int location)
Parameters
location
intThe variable whose value is to be decremented.
Returns
- int
The decremented value.
Exchange(ref int, int)
Sets a 32-bit signed integer to a specified value and returns the original value, as an atomic operation.
public static int Exchange(ref int location1, int value)
Parameters
location1
intThe variable to set to the specified value.
value
intThe value to which the location1 parameter is set.
Returns
- int
The original value of location1.
Increment(ref int)
Increments a specified variable and stores the result, as an atomic operation.
public static int Increment(ref int location)
Parameters
location
intThe variable whose value is to be incremented.
Returns
- int
The incremented value.