↧
Answer by Valery Petrov for Lockfree Read value after Interlocked.Exchange?
If you want to read the latest available value, you should use something like Interlocked.CompareExchange(ref bar, null, null). Checking for null is just for satisfying CompareExchange signature (if...
View ArticleAnswer by xanatos for Lockfree Read value after Interlocked.Exchange?
You are missing the point...Unless you do: public void OtherStuffFromThread2(){ while (true) { //how do I ensure that I have the latest bar ref here //considering mem cahces etc bar.Something(); }}That...
View ArticleLockfree Read value after Interlocked.Exchange?
Lets say we have a class like so:public class Foo{ private Bar bar = new Bar(); public void DoStuffInThread1() { var old = Interlocked.Exchange(ref bar,new Bar()); //do things with old //everything is...
View Article