public void GetSet()
        {
            bool mark;
            AtomicMarkableReference <T> ai = new AtomicMarkableReference <T>(one, false);

            Assert.AreEqual(one, ai.Value);
            Assert.IsFalse(ai.IsMarked);
            Assert.AreEqual(one, ai.GetValue(out mark));
            Assert.IsFalse(mark);
            ai.SetNewAtomicValue(two, false);
            Assert.AreEqual(two, ai.Value);
            Assert.IsFalse(ai.IsMarked);
            Assert.AreEqual(two, ai.GetValue(out mark));
            Assert.IsFalse(mark);
            ai.SetNewAtomicValue(one, true);
            Assert.AreEqual(one, ai.Value);
            Assert.IsTrue(ai.IsMarked);
            Assert.AreEqual(one, ai.GetValue(out mark));
            Assert.IsTrue(mark);

            ai.SetNewAtomicValue(one, true);
            Assert.AreEqual(one, ai.Value);
            Assert.IsTrue(ai.IsMarked);
            Assert.AreEqual(one, ai.GetValue(out mark));
            Assert.IsTrue(mark);
        }
        public void AttemptMark()
        {
            bool mark;
            AtomicMarkableReference <T> ai = new AtomicMarkableReference <T>(one, false);

            Assert.IsFalse(ai.IsMarked, "Reference is marked.");
            Assert.IsTrue(ai.AttemptMark(one, true), "Reference was not marked");
            Assert.IsTrue(ai.IsMarked, "Reference is not marked.");
            Assert.AreEqual(one, ai.GetValue(out mark), "Reference does not equal.");
            Assert.IsTrue(mark, "Mark returned is false");
        }
        public void DefaultConstructor()
        {
            AtomicMarkableReference <T> ai = new AtomicMarkableReference <T>(one, false);

            Assert.AreEqual(one, ai.Value);
            Assert.IsFalse(ai.IsMarked);
            AtomicMarkableReference <T> a2 = new AtomicMarkableReference <T>(null, true);

            Assert.IsNull(a2.Value);
            Assert.IsTrue(a2.IsMarked);
        }
        public void SerializeAndDeseralize()
        {
            AtomicMarkableReference <T> atomicMarkableReference = new AtomicMarkableReference <T>(one, true);
            MemoryStream bout = new MemoryStream(10000);

            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(bout, atomicMarkableReference);

            MemoryStream                bin        = new MemoryStream(bout.ToArray());
            BinaryFormatter             formatter2 = new BinaryFormatter();
            AtomicMarkableReference <T> atomicMarkableReference2 = (AtomicMarkableReference <T>)formatter2.Deserialize(bin);

            Assert.AreEqual(atomicMarkableReference.Value, atomicMarkableReference2.Value);
            Assert.IsTrue(atomicMarkableReference2.IsMarked);
        }
        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);
        }