9127a0b
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.
9127a0b
Run this on jvm and get
Exception in thread "main" You can't run this loop from a different threadThe 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.