How can I make this general? Class atomic reference (private object _ value; public atomic reference) {_value = new object ();} public atomic reference (object value) {optimistic set (value);} public object comparison Osset (object new value) {return interlock.change (referee_value, new vele)}} Public Zero OptimisticSet {object} while {_value == Interlocked.CompareExchange (reference _value, _value, newValue))} public Obtain object () {return _value;}}
My unsuccessful attempt:
class atomic references {private t _value; public atomic reference} {} public atomic reference (t value) {set (value);} Public T Compare EndSet (T New Value) {// _value is not an object that can be interlocked returns. Exchange (ref _ value, new value);} Public Zero OptimisticSet (T newValue) {// operator Can not use with == type T do {} while (_value == compare Andset (newValue));} Get Public T () {Return _value; }}
You need T
for reference Type, like this:
class atomic references & lt; T & gt; Where T: Square {Private T _value; Public atomic references () {} Public Nuclear Reference (T-Value) {Optimized Set (Value); } Public T Compare Endset (T New Vale) {Return Interlocked.Exchange (ref_value, newValue); } Public Zero OptimisticSet (T newValue) {while (_value == Compare and set newvalue); } Get Public T () {Return _value; }} Edit : I would suggest that you change the ways of a property: {Quantity of returns; } Set {while (_value == compare and set (value)); }}
No comments:
Post a Comment