haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Atomic shims for sys targets

Open Aidan63 opened this issue 8 months ago • 3 comments

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?

Aidan63 avatar Jul 01 '25 21:07 Aidan63

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.

Simn avatar Jul 02 '25 04:07 Simn

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.

Apprentice-Alchemist avatar Jul 02 '25 09:07 Apprentice-Alchemist

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

Apprentice-Alchemist avatar Jul 04 '25 15:07 Apprentice-Alchemist