I'm maintaining a high performance class that can be operated on by multiple threads. Many of the fields are volatile ints, and as it turns out I need to upgrade one of those to a double. I'm curious if there is a lock free way to do this, and was wondering if the Interlocked.CompareExchange(double, double, double)
works as advertised on a 32-bit OS, or are torn reads a problem.
views:
65answers:
2
+1
A:
Yes, it works as described on 32-bit. That's what the Interlocked
methods are there for.
LukeH
2009-12-17 16:27:40
+1
A:
This page details the intrinsics of the "native" Interlocked functions. It mentions the following limitations
*Because InterlockedCompareExchange64 uses the cmpxchg8b instruction, it is not available on pre-Pentium processors, such as the 486.
So we can expect that it is available and also implemented as an interlocked instruction operation (rather than being simulated by using a full lock).
peterchen
2009-12-17 16:40:16