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

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

774 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.


3 comments

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

dpeterson
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).

tom103
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).