public void LockUnicityTest() { ParallelTestHelper.Repeat(delegate { int currentCount = 0; bool fail = false; SpinLockWrapper wrapper = new SpinLockWrapper(); ParallelTestHelper.ParallelStressTest(wrapper, delegate { bool taken = false; wrapper.Lock.Enter(ref taken); int current = currentCount++; if (current != 0) fail = true; SpinWait sw = new SpinWait(); for (int i = 0; i < 200; i++) sw.SpinOnce(); currentCount -= 1; wrapper.Lock.Exit(); }, 4); Assert.IsFalse(fail); }, 200); }