Skip to content

[jvm] haxe.EventLoop.main fails if first accessed from non-main thread #12985

Description

@kevinresol

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions