本文整理汇总了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);
}
示例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()));
}
示例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);
}
示例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);
}
示例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);
}
示例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()));
}