public void CompareAndSetInMultipleThreadsChangedMarkBits()
        {
            AtomicMarkableReference <T> ai = new AtomicMarkableReference <T>(one, false);
            Thread t = new Thread(delegate()
            {
                while (!ai.CompareAndSet(one, one, true, false))
                {
                    Thread.Sleep(Delays.Short);
                }
            });

            t.Start();
            Assert.IsTrue(ai.CompareAndSet(one, one, false, true));
            t.Join(Delays.Long);
            Assert.IsFalse(t.IsAlive);
            Assert.AreEqual(ai.Value, one);
            Assert.IsFalse(ai.IsMarked);
        }
        public void CompareAndSet()
        {
            bool mark;
            AtomicMarkableReference <T> ai = new AtomicMarkableReference <T>(one, false);

            Assert.AreEqual(one, ai.GetValue(out mark));
            Assert.IsFalse(ai.IsMarked);
            Assert.IsFalse(mark);

            Assert.IsTrue(ai.CompareAndSet(one, two, false, false));
            Assert.AreEqual(two, ai.GetValue(out mark));
            Assert.IsFalse(mark);

            Assert.IsTrue(ai.CompareAndSet(two, m3, false, true));
            Assert.AreEqual(m3, ai.GetValue(out mark));
            Assert.IsTrue(mark);

            Assert.IsFalse(ai.CompareAndSet(two, m3, true, true));
            Assert.AreEqual(m3, ai.GetValue(out mark));
            Assert.IsTrue(mark);
        }