Mercurial > hg > Database > jungle-sharp
comparison src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/transaction/AtomicReference.cs @ 17:01a08cf4b2d9
Liq Files
author | Kazuma |
---|---|
date | Mon, 07 Nov 2016 01:05:24 +0900 |
parents | abe0c247f5a5 |
children | faa8a0c1492e |
comparison
equal
deleted
inserted
replaced
16:8f1ce942abfc | 17:01a08cf4b2d9 |
---|---|
1 using System.Threading; | |
2 | |
3 public class AtomicReference <T> where T : class { | |
4 private T value; | |
5 | |
6 public AtomicReference(T value) { | |
7 this.value = value; | |
8 } | |
9 | |
10 public bool CompareAndSet(T newValue, T prevValue) { | |
11 // change to compere exchange. | |
12 T oldValue = value; | |
13 return (oldValue != Interlocked.CompareExchange (ref value, newValue, prevValue)); | |
14 } | |
15 | |
16 | |
17 public T Get() { | |
18 return value; | |
19 } | |
20 } |