public void AtomicReferenceArray_Store_MemoryOrder_Should_Success(MemoryOrder order) { var source = Enumerable.Range(0, 3).Select(x => new object()).ToArray(); var atomicReferenceArray = new AtomicReferenceArray <object>(source.Length, order); for (int i = 0; i < atomicReferenceArray.Count; i++) { atomicReferenceArray.Store(i, source[i], order); } for (int i = 0; i < atomicReferenceArray.Count; i++) { Assert.Equal(source[i], atomicReferenceArray.Load(i, order)); } for (int i = 0; i < atomicReferenceArray.Count; i++) { atomicReferenceArray.Store(i, source[i], order); } for (int i = 0; i < atomicReferenceArray.Count; i++) { Assert.Equal(source[i], atomicReferenceArray.Load(i, order)); } }
public void AtomicReferenceArray_Store_Should_Fail() { var atomicReferenceArray = new AtomicReferenceArray <object>(new object[1]); Assert.Throws <InvalidOperationException>(() => atomicReferenceArray.Store(0, new object(), MemoryOrder.Acquire)); #pragma warning disable 618 Assert.Throws <NotSupportedException>(() => atomicReferenceArray.Store(0, new object(), MemoryOrder.Consume)); #pragma warning restore 618 }
public void AtomicReferenceArray_Store_Should_Success(object initialValue, object storeValue, MemoryOrder order) { var atomicReferenceArray = new AtomicReferenceArray <object>(new object[1], MemoryOrder.Relaxed); atomicReferenceArray.Store(0, storeValue, order); Assert.Equal(storeValue, atomicReferenceArray[0]); }