Skip to content

Exit proxied main with its status when keepalives run out - #27731

Open
servusdei2018 wants to merge 2 commits into
emscripten-core:mainfrom
servusdei2018:bracyn/27721
Open

servusdei2018 wants to merge 2 commits into
emscripten-core:mainfrom
servusdei2018:bracyn/27721

Conversation

@servusdei2018

Copy link
Copy Markdown

With -pthread -sPROXY_TO_PTHREAD -sEXIT_RUNTIME, a main() that returns while a runtime keepalive is held now exits with its status once the count reaches zero, instead of exiting 0 with atexit handlers skipped.

Fixes #27721

With -pthread -sPROXY_TO_PTHREAD -sEXIT_RUNTIME, a main() that returns while a runtime keepalive is held now exits with its status once the count reaches zero, instead of exiting 0 with atexit handlers skipped.

Fixes emscripten-core#27721

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fixing this is great idea, but I wonder if we can simplify this solution a little?

Comment thread src/lib/libcore.js Outdated
Comment thread src/lib/libcore.js
if (proxiedMainDone) {
proxiedMainDone = false;
exitOnMainThread(proxiedMainExitCode);
return;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this return needed? i.e. can we just rely on the return on line 2216?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so; falling through calls __emscripten_thread_exit(), which tries to post a message to the main thread right as the worker is being terminated, causing a received "6" command from terminated worker error in assertion builds.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we replace proxiedMainDone with isProxiedMainThread? This could be simple boolean what is true only on the proxied main thread.

This could then just be if (proxiedMainDone) exitOnMainThread(EXITSTATUS);

I don't think we need to track whether or not the main is done because if we get to this locaiton in the code its is by definition done.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, because if this I think we can maybe remove the exit(rtn) call from _main_thread, and just always rely on this maybeExit path to handle calling exit?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better still, maybe we can replace the if (ENVIRONMENT_IS_PTHREAD) { just above with if (ENVIRONMENT_IS_PTHREAD && !isProxiedMainThread) {`` .. then the existing (_exit`) below should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PROXY_TO_PTHREAD: runtime never exits when the proxied main thread's keepalive drops to 0 after main returns

2 participants