Open
Description
While working on #92974, I've realised that on some platforms without builtin atomics for all types, compilers might use a locking based implementation for them.
Checking the C11 defines, it seems like at least ARM32 is affected with Clang, but other platforms might be affected with GCC too.
Looking at the exact codegen, ARM32 and ARM 8.0 without atomics seem to use helper calls for Interlocked, only arm32 gives warnings about locking though.
The code should be fixed to avoid potential issues with this, I see 4 possible solutions:
- Make the helper calls QCalls - expensive
- Switch to preemptive in the FCall on affected platforms - also expensive
- Implement Interlocked with always expand intrinsics on affected platforms - requires JIT work (should already be handled on ARM 8.0 in .NET 9)
- Rewrite the unmanaged helpers in raw assembly in a way that doesn't use locks - requires VM work
Relying on the compiler to be lock free on any platform that uses helper calls for atomics seems unreliable as AFAIR those are free to implement them using locks.
cc @jkotas