.net - C# volatile array items? -
I need an array with unstable objects, and there can be no way to do this.
Personal volatile T [] _arr;
This means that the _arr reference is unstable, although it does not guarantee certain things about things.
What are the RR items as volatile?
Thank you.
Edit:
The following code generated according to the answer of binarycode. Is this code safe to use thread?
Public class VolatileArray & lt; T & gt; {Private T [] _arr; Public VolatileArray (int length) {_arr = New T [length]; } Public Voltairerre (t [] arr) {_arr = arr; } Public t this [int index] {find {t value = _arr [index]; Thread.MemoryBarrier (); return value; } Set {Thread.MemoryBarrier (); _arr [index] = value; }} Public int length {received {return _arr.Length; It is possible to pass the array elements from the context, so you can use it. You can thread.wallatle read
and thread.wallattildrights
. It is useful to understand that unstable
works behind the curtain using the thread. MemoryBarrier
You can type:
// read x = _arr [i]; Thread.MemoryBarrier (); // Write Thread.MomoriBarrier (); _RR [I] = X;
Note that unstable
and MemoryBarrier are advanced technologies which are both easy to go wrong. For example, see. Generally, you are better off with high level construction such as lock
, monitor
, ReaderWriterLockSlim
, and others.
Comments
Post a Comment