mscorlib(4.0.0.0) API with additions
System.Threading.Interlocked Class Reference

Provides atomic operations for variables that are shared by multiple threads. More...

Public Member Functions

static int Exchange (ref int location1, int value)
 Sets a 32-bit signed integer to a specified value and returns the original value, as an atomic operation. More...
 
static long Exchange (ref long location1, long value)
 Sets a 64-bit signed integer to a specified value and returns the original value, as an atomic operation. More...
 
static float Exchange (ref float location1, float value)
 Sets a single-precision floating point number to a specified value and returns the original value, as an atomic operation. More...
 
static double Exchange (ref double location1, double value)
 Sets a double-precision floating point number to a specified value and returns the original value, as an atomic operation. More...
 
static object Exchange (ref object location1, object value)
 Sets an object to a specified value and returns a reference to the original object, as an atomic operation. More...
 
static IntPtr Exchange (ref IntPtr location1, IntPtr value)
 Sets a platform-specific handle or pointer to a specified value and returns the original value, as an atomic operation. More...
 
static int CompareExchange (ref int location1, int value, int comparand)
 Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value. More...
 
static long CompareExchange (ref long location1, long value, long comparand)
 Compares two 64-bit signed integers for equality and, if they are equal, replaces the first value. More...
 
static float CompareExchange (ref float location1, float value, float comparand)
 Compares two single-precision floating point numbers for equality and, if they are equal, replaces the first value. More...
 
static double CompareExchange (ref double location1, double value, double comparand)
 Compares two double-precision floating point numbers for equality and, if they are equal, replaces the first value. More...
 
static object CompareExchange (ref object location1, object value, object comparand)
 Compares two objects for reference equality and, if they are equal, replaces the first object. More...
 
static IntPtr CompareExchange (ref IntPtr location1, IntPtr value, IntPtr comparand)
 Compares two platform-specific handles or pointers for equality and, if they are equal, replaces the first one. More...
 

Static Public Member Functions

static int Increment (ref int location)
 Increments a specified variable and stores the result, as an atomic operation. More...
 
static long Increment (ref long location)
 Increments a specified variable and stores the result, as an atomic operation. More...
 
static int Decrement (ref int location)
 Decrements a specified variable and stores the result, as an atomic operation. More...
 
static long Decrement (ref long location)
 Decrements the specified variable and stores the result, as an atomic operation. More...
 
static T Exchange< T > (ref T location1, T value)
 Sets a variable of the specified type T to a specified value and returns the original value, as an atomic operation. More...
 
static T CompareExchange< T > (ref T location1, T value, T comparand)
 Compares two instances of the specified reference type T for equality and, if they are equal, replaces the first one. More...
 
static int Add (ref int location1, int value)
 Adds two 32-bit integers and replaces the first integer with the sum, as an atomic operation. More...
 
static long Add (ref long location1, long value)
 Adds two 64-bit integers and replaces the first integer with the sum, as an atomic operation. More...
 
static long Read (ref long location)
 Returns a 64-bit value, loaded as an atomic operation. More...
 
static void MemoryBarrier ()
 Synchronizes memory access as follows: The processor that executes the current thread cannot reorder instructions in such a way that memory accesses before the call to M:System.Threading.Interlocked.MemoryBarrier execute after memory accesses that follow the call to M:System.Threading.Interlocked.MemoryBarrier. More...
 

Detailed Description

Provides atomic operations for variables that are shared by multiple threads.

Definition at line 10 of file Interlocked.cs.

Member Function Documentation

◆ Add() [1/2]

static int System.Threading.Interlocked.Add ( ref int  location1,
int  value 
)
static

Adds two 32-bit integers and replaces the first integer with the sum, as an atomic operation.

Parameters
location1A variable containing the first value to be added. The sum of the two values is stored in location1 .
valueThe value to be added to the integer at location1 .
Returns
The new value stored at location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

Definition at line 247 of file Interlocked.cs.

◆ Add() [2/2]

static long System.Threading.Interlocked.Add ( ref long  location1,
long  value 
)
static

Adds two 64-bit integers and replaces the first integer with the sum, as an atomic operation.

Parameters
location1A variable containing the first value to be added. The sum of the two values is stored in location1 .
valueThe value to be added to the integer at location1 .
Returns
The new value stored at location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

Definition at line 259 of file Interlocked.cs.

◆ CompareExchange() [1/6]

static int System.Threading.Interlocked.CompareExchange ( ref int  location1,
int  value,
int  comparand 
)

Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.

Parameters
location1The destination, whose value is compared with comparand and possibly replaced.
valueThe value that replaces the destination value if the comparison results in equality.
comparandThe value that is compared to the value at location1 .
Returns
The original value in location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

◆ CompareExchange() [2/6]

static long System.Threading.Interlocked.CompareExchange ( ref long  location1,
long  value,
long  comparand 
)

Compares two 64-bit signed integers for equality and, if they are equal, replaces the first value.

Parameters
location1The destination, whose value is compared with comparand and possibly replaced.
valueThe value that replaces the destination value if the comparison results in equality.
comparandThe value that is compared to the value at location1 .
Returns
The original value in location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

◆ CompareExchange() [3/6]

static float System.Threading.Interlocked.CompareExchange ( ref float  location1,
float  value,
float  comparand 
)

Compares two single-precision floating point numbers for equality and, if they are equal, replaces the first value.

Parameters
location1The destination, whose value is compared with comparand and possibly replaced.
valueThe value that replaces the destination value if the comparison results in equality.
comparandThe value that is compared to the value at location1 .
Returns
The original value in location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

◆ CompareExchange() [4/6]

static double System.Threading.Interlocked.CompareExchange ( ref double  location1,
double  value,
double  comparand 
)

Compares two double-precision floating point numbers for equality and, if they are equal, replaces the first value.

Parameters
location1The destination, whose value is compared with comparand and possibly replaced.
valueThe value that replaces the destination value if the comparison results in equality.
comparandThe value that is compared to the value at location1 .
Returns
The original value in location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

◆ CompareExchange() [5/6]

static object System.Threading.Interlocked.CompareExchange ( ref object  location1,
object  value,
object  comparand 
)

Compares two objects for reference equality and, if they are equal, replaces the first object.

Parameters
location1The destination object that is compared with comparand and possibly replaced.
valueThe object that replaces the destination object if the comparison results in equality.
comparandThe object that is compared to the object at location1 .
Returns
The original value in location1 .
Exceptions
T:System.ArgumentNullExceptionThe address of location1 is a null pointer.

◆ CompareExchange() [6/6]

static IntPtr System.Threading.Interlocked.CompareExchange ( ref IntPtr  location1,
IntPtr  value,
IntPtr  comparand 
)

Compares two platform-specific handles or pointers for equality and, if they are equal, replaces the first one.

Parameters
location1The destination T:System.IntPtr, whose value is compared with the value of comparand and possibly replaced by value .
valueThe T:System.IntPtr that replaces the destination value if the comparison results in equality.
comparandThe T:System.IntPtr that is compared to the value at location1 .
Returns
The original value in location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

◆ CompareExchange< T >()

static T System.Threading.Interlocked.CompareExchange< T > ( ref T  location1,
value,
comparand 
)
static

Compares two instances of the specified reference type T for equality and, if they are equal, replaces the first one.

Parameters
location1The destination, whose value is compared with comparand and possibly replaced. This is a reference parameter (ref in C#, ByRef in Visual Basic).
valueThe value that replaces the destination value if the comparison results in equality.
comparandThe value that is compared to the value at location1 .
Template Parameters
TThe type to be used for location1 , value , and comparand . This type must be a reference type.
Returns
The original value in location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.
Type Constraints
T :class 

Definition at line 217 of file Interlocked.cs.

◆ Decrement() [1/2]

static int System.Threading.Interlocked.Decrement ( ref int  location)
static

Decrements a specified variable and stores the result, as an atomic operation.

Parameters
locationThe variable whose value is to be decremented.
Returns
The decremented value.
Exceptions
T:System.ArgumentNullExceptionThe address of location is a null pointer.

Definition at line 40 of file Interlocked.cs.

◆ Decrement() [2/2]

static long System.Threading.Interlocked.Decrement ( ref long  location)
static

Decrements the specified variable and stores the result, as an atomic operation.

Parameters
locationThe variable whose value is to be decremented.
Returns
The decremented value.
Exceptions
T:System.ArgumentNullExceptionThe address of location is a null pointer.

Definition at line 50 of file Interlocked.cs.

◆ Exchange() [1/6]

static int System.Threading.Interlocked.Exchange ( ref int  location1,
int  value 
)

Sets a 32-bit signed integer to a specified value and returns the original value, as an atomic operation.

Parameters
location1The variable to set to the specified value.
valueThe value to which the location1 parameter is set.
Returns
The original value of location1 .
Exceptions
T:System.ArgumentNullExceptionThe address of location1 is a null pointer.

◆ Exchange() [2/6]

static long System.Threading.Interlocked.Exchange ( ref long  location1,
long  value 
)

Sets a 64-bit signed integer to a specified value and returns the original value, as an atomic operation.

Parameters
location1The variable to set to the specified value.
valueThe value to which the location1 parameter is set.
Returns
The original value of location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

◆ Exchange() [3/6]

static float System.Threading.Interlocked.Exchange ( ref float  location1,
float  value 
)

Sets a single-precision floating point number to a specified value and returns the original value, as an atomic operation.

Parameters
location1The variable to set to the specified value.
valueThe value to which the location1 parameter is set.
Returns
The original value of location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

◆ Exchange() [4/6]

static double System.Threading.Interlocked.Exchange ( ref double  location1,
double  value 
)

Sets a double-precision floating point number to a specified value and returns the original value, as an atomic operation.

Parameters
location1The variable to set to the specified value.
valueThe value to which the location1 parameter is set.
Returns
The original value of location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

◆ Exchange() [5/6]

static object System.Threading.Interlocked.Exchange ( ref object  location1,
object  value 
)

Sets an object to a specified value and returns a reference to the original object, as an atomic operation.

Parameters
location1The variable to set to the specified value.
valueThe value to which the location1 parameter is set.
Returns
The original value of location1 .
Exceptions
T:System.ArgumentNullExceptionThe address of location1 is a null pointer.

◆ Exchange() [6/6]

static IntPtr System.Threading.Interlocked.Exchange ( ref IntPtr  location1,
IntPtr  value 
)

Sets a platform-specific handle or pointer to a specified value and returns the original value, as an atomic operation.

Parameters
location1The variable to set to the specified value.
valueThe value to which the location1 parameter is set.
Returns
The original value of location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.

◆ Exchange< T >()

static T System.Threading.Interlocked.Exchange< T > ( ref T  location1,
value 
)
static

Sets a variable of the specified type T to a specified value and returns the original value, as an atomic operation.

Parameters
location1The variable to set to the specified value. This is a reference parameter (ref in C#, ByRef in Visual Basic).
valueThe value to which the location1 parameter is set.
Template Parameters
TThe type to be used for location1 and value . This type must be a reference type.
Returns
The original value of location1 .
Exceptions
T:System.NullReferenceExceptionThe address of location1 is a null pointer.
Type Constraints
T :class 

Definition at line 127 of file Interlocked.cs.

◆ Increment() [1/2]

static int System.Threading.Interlocked.Increment ( ref int  location)
static

Increments a specified variable and stores the result, as an atomic operation.

Parameters
locationThe variable whose value is to be incremented.
Returns
The incremented value.
Exceptions
T:System.NullReferenceExceptionThe address of location is a null pointer.

Definition at line 18 of file Interlocked.cs.

◆ Increment() [2/2]

static long System.Threading.Interlocked.Increment ( ref long  location)
static

Increments a specified variable and stores the result, as an atomic operation.

Parameters
locationThe variable whose value is to be incremented.
Returns
The incremented value.
Exceptions
T:System.NullReferenceExceptionThe address of location is a null pointer.

Definition at line 29 of file Interlocked.cs.

◆ MemoryBarrier()

static void System.Threading.Interlocked.MemoryBarrier ( )
static

Synchronizes memory access as follows: The processor that executes the current thread cannot reorder instructions in such a way that memory accesses before the call to M:System.Threading.Interlocked.MemoryBarrier execute after memory accesses that follow the call to M:System.Threading.Interlocked.MemoryBarrier.

Definition at line 276 of file Interlocked.cs.

◆ Read()

static long System.Threading.Interlocked.Read ( ref long  location)
static

Returns a 64-bit value, loaded as an atomic operation.

Parameters
locationThe 64-bit value to be loaded.
Returns
The loaded value.

Definition at line 268 of file Interlocked.cs.


The documentation for this class was generated from the following file: