public class BlockingCell

Summary

A thread-safe single-assignment reference cell.

Remarks

A fresh BlockingCell holds no value (is empty). Any thread reading the Value property when the cell is empty will block until a value is made available by some other thread. The Value property can only be set once - on the first call, the BlockingCell is considered full, and made immutable. Further attempts to set Value result in a thrown InvalidOperationException.

Property Summary

Flags Type Name Summary
public object Value (rw)

Retrieve the cell's value, blocking if none exists at present, or supply a value to an empty cell, thereby filling it.

Constructor Summary

Flags Name Summary
public BlockingCell()

Construct an empty BlockingCell.

Method Summary

Flags Name Summary
public bool GetValue(int millisecondsTimeout, out object result)

Retrieve the cell's value, waiting for the given timeout if no value is immediately available.

public static int validatedTimeout(int timeout)

Return valid timeout value

Property Detail

public object Value (rw)

Summary

Retrieve the cell's value, blocking if none exists at present, or supply a value to an empty cell, thereby filling it.

Exception

Constructor Detail

BlockingCell

public BlockingCell()

Summary

Construct an empty BlockingCell.

Method Detail

GetValue

public bool GetValue(int millisecondsTimeout, out object result)

Flags public
Return type bool
Parameters
Name Type
millisecondsTimeout int
result out object

Summary

Retrieve the cell's value, waiting for the given timeout if no value is immediately available.

Remarks

If a value is present in the cell at the time the call is made, the call will return immediately. Otherwise, the calling thread blocks until either a value appears, or millisecondsTimeout milliseconds have elapsed.

Returns true in the case that the value was available before the timeout, in which case the out parameter "result" is set to the value itself.

If no value was available before the timeout, returns false, and sets "result" to null.

A timeout of -1 (i.e. System.Threading.Timeout.Infinite) will be interpreted as a command to wait for an indefinitely long period of time for the cell's value to become available. See the MSDN documentation for System.Threading.Monitor.Wait(object,int).

validatedTimeout

public static int validatedTimeout(int timeout)

Flags public static
Return type int
Parameters
Name Type
timeout int

Summary

Return valid timeout value

Remarks

If value of the parameter is less then zero, return 0 to mean infinity