C#/.NET Little Wonders: Interlocked CompareExchange()

added by BlackRabbitCoder
9/7/2012 3:18:45 PM

9 Kicks, 445 Views

This week, we’ll round out the discussion by talking about the Interlocked CompareExchange() method and how it can be put to use to exchange a value if the current value is what you expected it to be.


9/6/2012 7:37:02 PM
new post!

9/7/2012 3:18:53 PM
It's funny, I was *just* looking at this today. For my uses though, I actually ended up going with a simpler solution (volatile bool).

9/7/2012 4:09:24 PM
Good explanation!
Just a remark, though: for money, we usually use decimal, not double... and Interlocked.CompareExchange doesn't seem to support decimal (there is a generic overload, but it only accepts reference types).