Skip to content

Automatically asyncify a main with arguments. #18252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 29, 2022

Conversation

brendandahl
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

lgtm % comment

@with_asyncify_and_stack_switching
def test_async_main(self):
# needs to flush stdio streams
self.set_setting('EXIT_RUNTIME')
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you add a newline to the end of the printf then maybe you can remove this line?

#include <stdio.h>
#include <emscripten.h>
int main(int argc, char **argv) {
emscripten_sleep(1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

use usleep(1000) instead and avoid the emscripten-specific function/include? Maybe not worth it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

emscripten_sleep is Asyncify-enabled function (it suspends via Asyncify), while usleep, IIRC, actually blocks the main thread with a spin-loop, so wouldn't be suitable for a test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If true, that seems like something we might want to fix. Shouldn't all sleep functions should be Asyncify-enabled when running in Asyncify mode no?

Looking at the details it does looks like you are right though usleep -> nanosleep -> emscripten_thread_sleep -> emscripten_futex_wait, and as far as I know emscripten_futex_wait is not Asyncify-enabled.

I wonder if emscripten_thread_sleep or maybe even emscripten_futex_wait should be Asyncify-enabled?

Copy link
Collaborator

Choose a reason for hiding this comment

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

(I guess emscripten_thread_sleep and not emscripten_futex_wait.. since the later is used in many different places, but emscripten_thread_sleep is basically just used to implement clock_nanosleep).

Copy link
Collaborator

@RReverser RReverser Nov 28, 2022

Choose a reason for hiding this comment

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

Shouldn't all sleep functions should be Asyncify-enabled when running in Asyncify mode no?

Heh yeah I think I suggested that a while ago too but can't find an issue.

Same for other APIs that do potentially async work - currently we have a somewhat inconsistent mix of "will block while waiting for the result", "will run async on a separate thread" and "will run async via Asyncify", e.g. see #12255.

@brendandahl brendandahl merged commit 0c10ba8 into emscripten-core:main Nov 29, 2022
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.

3 participants