Table of Contents

Class Interlocked

Namespace
System.Threading
Assembly
mscorlib.dll

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 int

The destination, whose value is compared with comparand and possibly replaced.

value int

The value that replaces the destination value if the comparison results in equality.

comparand int

The 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 int

The 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 int

The variable to set to the specified value.

value int

The 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 int

The variable whose value is to be incremented.

Returns

int

The incremented value.