Int64 (long) and Thread Safety Int64 (long) and Thread Safety multithreading multithreading

Int64 (long) and Thread Safety


Possibly, but why would you write a program that will be thread safe on some Intel workalike platforms, but not others? Note that the Decimal and Double types also have this disclaimer about thread safety.

Microsoft recommends the use of locks in these cases. There are links to some good information about concurrency, memory mapping and low-level locks here:

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/f03ea3c9-4c2b-4a79-8f8c-4a6b7476b20d


Memory load/store operations are considered to be atomic if they are performed on memory chunks that are placed on aligned memory address and are not bigger than the native machine-sized pointer.
Meaning, at 64bit load/store operation on an aligned memory address will be atomic on a 64bit platform, but it won't be atomic on a 32bit platform.

Modern processors offers a special set of instructions (in .Net, most of them are exposed via the Interlocked class). that allow to achieve atomicity on load/store operations that are larger than the machine's native pointer size (64bit operations on 32bit processors, and 128bit operations on 64bit processors. The latter isn't exposed by the Interlocked class, but is available in native code).

For more details, check Joe Duffy's post: Thread-safety, torn reads, and the like.


It's a problem if your data variable is accessed directly by code from different threads.

They don't make guarantees about any specific system, so to be safe I'd assume it's not threadsafe on x64 systems as well as x86, though I suspect what they really had in mind was places like the compact framework running on smart phones.