HaxeFoundation / HaxeFoundation/haxe
[jvm] haxe.EventLoop.main fails if first accessed from non-main thread
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
9127a0b
```haxe
static function main() {
// trace(sys.thread.Thread.main()); // uncomment to fix
final t = new java.lang.Thread(() -> {
trace(sys.thread.Thread.current() == sys.thread.Thread.main()); // prints true?! huh?
trace(haxe.EventLoop.main.run(() -> trace("run in main loop")));
});
t.start();
t.join();
}
```
Run this on jvm and get `Exception in thread "main" You can't run this loop from a different thread`
The problem is that the static var that stores the main thread reference is run on the thread that first accessed it, so it might reference the wrong thread. In other words `sys.thread.Thread.main()` cannot reliably return the main thread unless it is first accessed from the main thread.
Contributor guide
Research direction
Start by reproducing the provided Haxe JVM example, then inspect the implementations of haxe.EventLoop.main and sys.thread.Thread.main that the report identifies. Confirm that accessing Thread.main first from the worker thread causes the failure; done means the example runs the callback in the main loop without requiring the commented workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100