public void GetSet()
        {
            int mark;
            AtomicStamped <T> ai = new AtomicStamped <T>(one, 0);

            Assert.AreEqual(one, ai.Value);
            Assert.AreEqual(0, ai.Stamp);
            Assert.AreEqual(one, ai.GetValue(out mark));
            Assert.AreEqual(0, mark);
            ai.SetNewAtomicValue(two, 0);
            Assert.AreEqual(two, ai.Value);
            Assert.AreEqual(0, ai.Stamp);
            Assert.AreEqual(two, ai.GetValue(out mark));
            Assert.AreEqual(0, mark);
            ai.SetNewAtomicValue(one, 1);
            Assert.AreEqual(one, ai.Value);
            Assert.AreEqual(1, ai.Stamp);
            Assert.AreEqual(one, ai.GetValue(out mark));
            Assert.AreEqual(1, mark);

            ai.SetNewAtomicValue(one, 1);
            Assert.AreEqual(one, ai.Value);
            Assert.AreEqual(1, ai.Stamp);
            Assert.AreEqual(one, ai.GetValue(out mark));
            Assert.AreEqual(1, mark);
        }
        public void AttemptStamp()
        {
            int mark;
            AtomicStamped <T> ai = new AtomicStamped <T>(one, 0);

            Assert.AreEqual(0, ai.Stamp);
            Assert.IsTrue(ai.AttemptStamp(one, 1));
            Assert.AreEqual(1, ai.Stamp);
            Assert.AreEqual(one, ai.GetValue(out mark));
            Assert.AreEqual(1, mark);
        }
        public void Constructor()
        {
            AtomicStamped <T> ai = new AtomicStamped <T>(one, 0);

            Assert.AreEqual(one, ai.Value);
            Assert.AreEqual(0, ai.Stamp);
            AtomicStamped <T> a2 = new AtomicStamped <T>(default(T), 1);

            Assert.That(a2.Value, Is.EqualTo(default(T)));
            Assert.AreEqual(1, a2.Stamp);
        }
        public void SerializeAndDeseralize()
        {
            AtomicStamped <T> atomicStamped = new AtomicStamped <T>(one, 0987654321);
            MemoryStream      bout          = new MemoryStream(10000);

            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(bout, atomicStamped);

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

            Assert.AreEqual(atomicStamped.Value, atomicStampedReference2.Value);
            Assert.AreEqual(atomicStamped.Stamp, atomicStampedReference2.Stamp);
        }
        public void CompareAndSetInMultipleThreads2()
        {
            AtomicStamped <T> ai = new AtomicStamped <T>(one, 0);
            Thread t = new Thread(delegate()
            {
                while (!ai.CompareAndSet(one, one, 1, 2))
                {
                    Thread.Sleep(0);
                }
            });

            t.Start();
            Assert.IsTrue(ai.CompareAndSet(one, one, 0, 1));
            t.Join(Delays.Long);
            Assert.IsFalse(t.IsAlive);
            Assert.AreEqual(ai.Value, one);
            Assert.AreEqual(ai.Stamp, 2);
        }
        public void CompareAndSet()
        {
            int mark;
            AtomicStamped <T> ai = new AtomicStamped <T>(one, 0);

            Assert.AreEqual(one, ai.GetValue(out mark));
            Assert.AreEqual(0, ai.Stamp);
            Assert.AreEqual(0, mark);

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

            Assert.IsTrue(ai.CompareAndSet(two, m3, 0, 1));
            Assert.AreEqual(m3, ai.GetValue(out mark));
            Assert.AreEqual(1, mark);

            Assert.IsFalse(ai.CompareAndSet(two, m3, 1, 1));
            Assert.AreEqual(m3, ai.GetValue(out mark));
            Assert.AreEqual(1, mark);
        }
        public void WeakCompareAndSet()
        {
            int mark;
            AtomicStamped <T> ai = new AtomicStamped <T>(one, 0);

            Assert.AreEqual(one, ai.GetValue(out mark));
            Assert.AreEqual(0, ai.Stamp);
            Assert.AreEqual(0, mark);

            while (!ai.WeakCompareAndSet(one, two, 0, 0))
            {
            }

            Assert.AreEqual(two, ai.GetValue(out mark));
            Assert.AreEqual(0, mark);

            while (!ai.WeakCompareAndSet(two, m3, 0, 1))
            {
            }

            Assert.AreEqual(m3, ai.GetValue(out mark));
            Assert.AreEqual(1, mark);
        }