コード例 #1
0
        public void AtomicObjectGetAndSetReturnsOriginalValueMultiThreaded()
        {
            const int expected = 1000;

            ConcurrentCountedSet <string> values = new ConcurrentCountedSet <string>();

            var o = new AtomicObject <string>("foo");

            System.Threading.Tasks.Parallel.For(0, 1000, i => values.Add(o.GetAndSet(i % 2 == 0 ? "bar" : "foo")));

            Assert.AreEqual(expected, values["foo"] + values["bar"]);
        }
コード例 #2
0
        public void AtomicObjectGetAndSetReturnsOriginalValue()
        {
            const int expected = 1000;

            ConcurrentCountedSet <string> values = new ConcurrentCountedSet <string>();

            var o = new AtomicObject <string>("foo");

            for (int i = 0; i < 1000; i++)
            {
                values.Add(o.GetAndSet(i % 2 == 0 ? "bar" : "foo"));
            }

            Assert.AreEqual(expected, values["foo"] + values["bar"]);
        }