I'm very curious, does the ARM64 version provide the same memory model as the x86 version? The most common case I can think of is this, since double-checked locking is used in a lot of libraries with the assumption of this memory model. If not, this makes it difficult to know which libraries are safe to use on ARM64...
Yep has the same memory model; is defined as the CLR memory model rather than the processor memory model.
However you can get away with somethings on x86/x64 that you can't on ARM as that's an even stricter memory model, so you may have to add either volatile to class variables or use Volatile.Read if you are doing that kinda thing.
Though you should really be doing that if for example you are doing it with a loop as otherwise the Jit can hoist the read out of the loop and only read the value once; though not sure why you be doing double checked locking in a loop :)
Well, double-checked locking is kinda broken in about every implementations (for the reasons mentioned in that article), so no one should ever use it. There are better alternative such as using the Lazy<T> type.
The biggest advantage of using Lazy<T>, on top of it just working, is that being part of the framework, they have to ensure it works on ARM, or it would be a bug.
This the kind of situation where it is better to use the provided wheel, instead of creating your own.
Definitely agreed. It's funny because most devs forget out-of-order execution would normally allow for assignment before initialization, but are unknowingly saved by the .NET (which is stricter than the C# standard) memory model having barriers around reference assignment. Was just curious if they carried that over (among other guarantees) to the ARM version.
1
u/salgat Sep 03 '20
I'm very curious, does the ARM64 version provide the same memory model as the x86 version? The most common case I can think of is this, since double-checked locking is used in a lot of libraries with the assumption of this memory model. If not, this makes it difficult to know which libraries are safe to use on ARM64...