Ejemplo n.º 1
0
        public unsafe void Test_ArrayExtensions_Pointer()
        {
            SpinLock  spinLock = default;
            SpinLock *p        = &spinLock;

            int sum = 0;

            Parallel.For(0, 1000, i =>
            {
                for (int j = 0; j < 10; j++)
                {
                    using (SpinLockExtensions.Enter(p))
                    {
                        sum++;
                    }
                }
            });

            Assert.AreEqual(sum, 1000 * 10);
        }
Ejemplo n.º 2
0
        public void Test_ArrayExtensions_Ref()
        {
            var spinLockOwner = new SpinLockOwner();

            int sum = 0;

            Parallel.For(0, 1000, i =>
            {
                for (int j = 0; j < 10; j++)
                {
#if WINDOWS_UWP
                    using (SpinLockExtensions.Enter(spinLockOwner, ref spinLockOwner.Lock))
#else
                    using (spinLockOwner.Lock.Enter())
#endif
                    {
                        sum++;
                    }
                }
            });

            Assert.AreEqual(sum, 1000 * 10);
        }