Exemple #1
0
        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));
            }
        }
Exemple #2
0
        public void AtomicReferenceArray_Load_Should_Fail()
        {
            var atomicReferenceArray = new AtomicReferenceArray <object>(new [] { new object() });

            Assert.Throws <InvalidOperationException>(() => atomicReferenceArray.Load(0, MemoryOrder.Release));
#pragma warning disable 618
            Assert.Throws <NotSupportedException>(() => atomicReferenceArray.Load(0, MemoryOrder.Consume));
#pragma warning restore 618
        }
Exemple #3
0
        public void AtomicReferenceArray_Load_Should_Success()
        {
            var obj = new object();
            var atomicReferenceArray = new AtomicReferenceArray <object>(new[] { obj });

            Assert.Equal(obj, atomicReferenceArray.Load(0, MemoryOrder.Relaxed));
            Assert.Equal(obj, atomicReferenceArray.Load(0, MemoryOrder.Acquire));
            Assert.Equal(obj, atomicReferenceArray.Load(0, MemoryOrder.AcqRel));
            Assert.Equal(obj, atomicReferenceArray.Load(0, MemoryOrder.SeqCst));
        }