Atomic shims for sys targets
Only four targets support atomics (jvm, hl, cpp, and js?!), but all sys targets could emulate them with a mutex. We've been doing that on the coroutine branch so we don't have to have #if blocks everywhere. Having a fallback implementation for sys targets seems quite useful outside of our coroutine stuff as it would remove the need for all those #if blocks in places such as here https://github.com/HaxeFoundation/haxe/pull/12292
I'm not sure how best to do this though since we can't do something like AtomicInt.sys.hx, add a #if sys block to the non target AtomicInt?
I was thinking about opening this issue as well, but then I thought that this would be easier if we had a cross-target Mutex version first. But thinking about it again now, that's not technically necessary because all threaded targets for which this matters already have a proper Mutex implementation (I think).
But yes I'm also unsure what to put where here.
Eval also has atomics now (https://github.com/HaxeFoundation/haxe/pull/12275), so out of the targets with threading that just leaves Neko and Python. Neko could have native support, that's just a question of adapting the HL implementation (and doing another Neko release). Python would either need to depend on an external library (be that an existing library or one we maintain ourselves) or fall back to a lock-based implementation.
Here's implementations for both Neko and Python:
- Python: https://github.com/Apprentice-Alchemist/haxe-python-atomic and https://github.com/Apprentice-Alchemist/haxe/tree/python-atomics
- Neko: https://github.com/Apprentice-Alchemist/neko/tree/atomics and https://github.com/Apprentice-Alchemist/haxe/tree/neko-atomic