[go: nahoru, domu]

Skip to content
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

Fix the handling of runtimeKeepalivePush() and runtimeKeepalivePop() in emscripten_set_immediate_loop() #18053

Merged

Conversation

juj
Copy link
Collaborator
@juj juj commented Oct 13, 2022

Fix the handling of runtimeKeepalivePush() and runtimeKeepalivePop() in emscripten_set_immediate_loop() to be watertight.

Copy link
Member
@kripken kripken left a comment

Choose a reason for hiding this comment

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

A push is still needed, I think, as in the other PR? But maybe I'm mixed up. @sbc100 ?

@sbc100
Copy link
Collaborator
sbc100 commented Oct 13, 2022

A push is still needed, I think, as in the other PR? But maybe I'm mixed up. @sbc100 ?

This looks good to me. The idea is that we want to keep the runtime alive as long as there is an outstanding timeout. Here we call reutimeKeeplivePush when we first set the timeout, and we only pop it if/when we fail set the timeout once again in the callback.

I won't if we can make a test case for this that fails with the old/broken code?

@sbc100
Copy link
Collaborator
sbc100 commented Oct 13, 2022

A push is still needed, I think, as in the other PR? But maybe I'm mixed up. @sbc100 ?

This looks good to me. The idea is that we want to keep the runtime alive as long as there is an outstanding timeout. Here we call reutimeKeeplivePush when we first set the timeout, and we only pop it if/when we fail set the timeout once again in the callback.

I won't if we can make a test case for this that fails with the old/broken code?

Actually looking more closely I don't see a bug in the old code. The new code maybe avoids the extra Pop/Push for each iterations, but the old code seems to be perfectly correct.

I do see one difference in that, under the old code, the value of the keepalive counter will be zero while the callback itself is run . This means that if the user called exit() during callback, the application would exit, rather than staying alive to service the next iteration of the loop.

With the new code the loop is still considered alive for the duration of the callback, so calls to exit won't actually exit the application during this time.

I think perhaps locally the new code make more sense, since it requires and explicit cancellation of the loop to exit the runtime.

@kripken
Copy link
Member
kripken commented Oct 13, 2022

Here we call reutimeKeeplivePush when we first set the timeout

But there is no push in the new code (the push is deleted, and the pop is moved around). Am I reading it wrong?

@sbc100
Copy link
Collaborator
sbc100 commented Oct 13, 2022

Here we call reutimeKeeplivePush when we first set the timeout

But there is no push in the new code (the push is deleted, and the pop is moved around). Am I reading it wrong?

The push is below on line 106. This push now remains active until one of the callbacks returns 0, which is this is the desired effect.

Copy link
Member
@kripken kripken left a comment

Choose a reason for hiding this comment

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

Thanks, sorry, I missed it was out of the visible diff...

…in emscripten_set_immediate_loop() to be watertight.
@juj juj force-pushed the fix_set_immediate_loop_keepalive_check branch from 58b35df to 68eb026 Compare January 19, 2023 12:05
@juj juj enabled auto-merge (squash) January 19, 2023 12:05
@juj juj merged commit 5290d53 into emscripten-core:main Jan 19, 2023
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.

None yet

3 participants