public void CompareExpectedValueAndSetNewValueInMultipleThreads() { AtomicLong ai = new AtomicLong(1); Thread t = ThreadManager.StartAndAssertRegistered( "T1", () => { while (!ai.CompareAndSet(2, 3)) Thread.Sleep(0); }); Assert.IsTrue(ai.CompareAndSet(1, 2)); ThreadManager.JoinAndVerify(Delays.Long); Assert.IsFalse(t.IsAlive); Assert.AreEqual(ai.Value, 3); }
public void CompareExpectedValueAndSetNewValue() { AtomicLong ai = new AtomicLong(1); Assert.IsTrue(ai.CompareAndSet(1, 2)); Assert.IsTrue(ai.CompareAndSet(2, -4)); Assert.AreEqual(-4, ai.Value); Assert.IsFalse(ai.CompareAndSet(-5, 7)); Assert.IsFalse((7 == ai.Value)); Assert.IsTrue(ai.CompareAndSet(-4, 7)); Assert.AreEqual(7, ai.Value); }
public void CompareExpectedValueAndSetNewValueInMultipleThreads() { AtomicLong ai = new AtomicLong(1); Thread t = ThreadManager.StartAndAssertRegistered( "T1", () => { while (!ai.CompareAndSet(2, 3)) { Thread.Sleep(0); } }); Assert.IsTrue(ai.CompareAndSet(1, 2)); ThreadManager.JoinAndVerify(Delays.Long); Assert.IsFalse(t.IsAlive); Assert.AreEqual(ai.Value, 3); }