当前位置: 首页>>代码示例>>C#>>正文


C# AtomicReference.CompareAndSet方法代码示例

本文整理汇总了C#中AtomicReference.CompareAndSet方法的典型用法代码示例。如果您正苦于以下问题:C# AtomicReference.CompareAndSet方法的具体用法?C# AtomicReference.CompareAndSet怎么用?C# AtomicReference.CompareAndSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AtomicReference的用法示例。


在下文中一共展示了AtomicReference.CompareAndSet方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Cache_should_not_reply_with_expired_but_not_yet_swept_out_entries

        public void Cache_should_not_reply_with_expired_but_not_yet_swept_out_entries()
        {
            var localClock = new AtomicReference<long>(0);
            var cache = new SimpleDnsCacheTestDouble(localClock);
            var cacheEntry = Dns.Resolved.Create("test.local", System.Net.Dns.GetHostEntry("127.0.0.1").AddressList);
            cache.Put(cacheEntry, 5000);

            cache.Cached("test.local").ShouldBe(cacheEntry);
            localClock.CompareAndSet(0, 4999);
            cache.Cached("test.local").ShouldBe(cacheEntry);
            localClock.CompareAndSet(4999, 5000);
            cache.Cached("test.local").ShouldBe(null);

        }
开发者ID:skotzko,项目名称:akka.net,代码行数:14,代码来源:SimpleDnsCacheSpec.cs

示例2: CompareAndSet_when_equal_returns_true

        public void CompareAndSet_when_equal_returns_true()
        {
            var expected = new object();
            var obj = new AtomicReference<object>(expected);

            Assert.IsTrue(obj.CompareAndSet(expected, new object()));
        }
开发者ID:ondfisk,项目名称:C5.Concurrent,代码行数:7,代码来源:AtomicReferenceTests.cs

示例3: CompareAndSet_when_not_equal_does_not_set_value

        public void CompareAndSet_when_not_equal_does_not_set_value()
        {
            var initial = new object();
            var obj = new AtomicReference<object>(initial);

            obj.CompareAndSet(new object(), new object());

            Assert.AreEqual(initial, obj.Value);
        }
开发者ID:ondfisk,项目名称:C5.Concurrent,代码行数:9,代码来源:AtomicReferenceTests.cs

示例4: Cache_should_sweep_out_expired_entries_on_cleanup

        public void Cache_should_sweep_out_expired_entries_on_cleanup()
        {
            var localClock = new AtomicReference<long>(0);
            var cache = new SimpleDnsCacheTestDouble(localClock);
            var cacheEntry = Dns.Resolved.Create("test.local", System.Net.Dns.GetHostEntry("127.0.0.1").AddressList);
            cache.Put(cacheEntry, 5000);

            cache.Cached("test.local").ShouldBe(cacheEntry);
            localClock.CompareAndSet(0, 5000);
            cache.Cached("test.local").ShouldBe(null);
            localClock.CompareAndSet(5000, 0);
            cache.Cached("test.local").ShouldBe(cacheEntry);
            localClock.CompareAndSet(0, 5000);
            cache.CleanUp();
            cache.Cached("test.local").ShouldBe(null);
            localClock.CompareAndSet(5000, 0);
            cache.Cached("test.local").ShouldBe(null);
           
        }
开发者ID:skotzko,项目名称:akka.net,代码行数:19,代码来源:SimpleDnsCacheSpec.cs

示例5: CompareAndSet_when_equal_sets_value

        public void CompareAndSet_when_equal_sets_value()
        {
            var oldValue = new object();
            var obj = new AtomicReference<object>(oldValue);
            var newValue = new object();

            obj.CompareAndSet(oldValue, newValue);

            Assert.AreEqual(newValue, obj.Value);
        }
开发者ID:ondfisk,项目名称:C5.Concurrent,代码行数:10,代码来源:AtomicReferenceTests.cs

示例6: CompareAndSet_when_not_equal_returns_false

        public void CompareAndSet_when_not_equal_returns_false()
        {
            var obj = new AtomicReference<object>();

            Assert.IsFalse(obj.CompareAndSet(new object(), new object()));
        }
开发者ID:ondfisk,项目名称:C5.Concurrent,代码行数:6,代码来源:AtomicReferenceTests.cs


注:本文中的AtomicReference.CompareAndSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。