static int Mul(ref int destination,int b)

Returns the product of 2 32-bit integers, and replaces the first number with the product, as an atomic operation. 

This method handles an overflow condition by wrapping: If the value at destination is int.MaxValue and value is 1, the result is int.MinValue and so on. No exception is thrown.


static long Mul(ref long destination, long b)

Returns the product of 2 64-bit integers, and replaces the first number with the product, as an atomic operation

This method handles an overflow condition by wrapping: If the value at destination is long.MaxValue and value is 1, the result is long.MinValue and so on. No exception is thrown.


static int Min(ref int destination, int b)

Returns the smaller of two 32-bit integers, and replaces the first number with the smaller value, as an atomic operation.


static long Min(ref long destination, long b)

Returns the smaller of two 64-bit integers, and replaces the first number with the smaller value, as an atomic operation.


static int Max(ref int destination, int b)

Returns the larger of two 32-bit integers, and replaces the first number with the larger value, as an atomic operation.


static long Max(ref long destination, long b)

Returns the larger of two 64-bit integers, and replaces the first number with the larger value, as an atomic operation.


static int And(ref int destination, int value)

Returns the bitwise AND of destination and value and stores the result in destination, as an atomic operation.


static int Or(ref int destination, int value)

Returns the bitwise OR of destination and value and stores the result in destination, as an atomic operation.


static int Xor(ref int destination, int value)

Returns the bitwise XOR of destination and value and stores the result in destination, as an atomic operation.


static byte TestBitAndSet(ref int destination, int position)

Examines bit position in destination and returns its current value.

The bit is set to 1 regardless of its current value.


static byte TestBitAndReset(ref int destination, int position)

Examines bit position in destination and returns its current value.

The bit is set to 0 regardless of its current value. 


static int ComputeAndSet(ref int destination,Predicate<int> criteria,Func<int,int> computation)

Checks if a 32-bit variable meets a specified criteria and possibly replaces it with a new value based on a specified computation.

This method generalizes atomic testing and setting a 32-bit variable by accepting external criteria and computation methods as parameters. 

The external methods should be fast and not time consuming, The longer time it takes to executes them the more likely other threads will alter the shared variable (destination) by the time they finish causing the methods to rerun and eventually causing the method to be ineffective and slow.


Last edited Dec 9, 2012 at 12:38 PM by brin_zohar, version 25

Comments

No comments yet.