Skip to content

Conversation

@kateinoigakukun
Copy link
Contributor

This commit adds a blocking-based poll_oneoff implementation to support clock_nanosleep in wasi-libc. This implementation is very simple and only supports a single subscription for now but is enough for clock_nanosleep to work.

: getNow() + timeout;
while (endTime > getNow()) {
// block until the timeout is reached
}
Copy link
Owner

@bjorn3 bjorn3 Feb 16, 2025

Choose a reason for hiding this comment

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

Not an ideal solution as this will block user interaction if it runs on the main thread and unnecessarily uses the cpu which especially on mobile devices is bad, but I guess there isn't really a better way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, JSPI could be a mitigation but I think it's too early to use it here

@bjorn3
Copy link
Owner

bjorn3 commented Jun 8, 2025

Sorry for the late reply. I completely forgot about this PR.

kateinoigakukun added a commit to kateinoigakukun/wasi-libc that referenced this pull request Jun 19, 2025
The `pthread_cond` test uses `nanosleep` which eventually calls
`poll_oneoff` but `@bjorn3/browser_wasi_shim` does not implement it.
So we skip the test for now, but we will revisit it later once
bjorn3/browser_wasi_shim#88 is merged.
@kateinoigakukun kateinoigakukun force-pushed the katei/add-poll-oneoff branch from e7fa8f9 to b8a84ba Compare June 19, 2025 23:34
This commit adds a blocking-based `poll_oneoff` implementation to support
`clock_nanosleep` in wasi-libc. This implementation is very simple and
only supports a single subscription for now but is enough for
`clock_nanosleep` to work.
@kateinoigakukun kateinoigakukun force-pushed the katei/add-poll-oneoff branch from b8a84ba to 836aae4 Compare June 19, 2025 23:37
@kateinoigakukun kateinoigakukun requested a review from bjorn3 June 19, 2025 23:45
sunfishcode pushed a commit to WebAssembly/wasi-libc that referenced this pull request Jun 20, 2025
The `pthread_cond` test uses `nanosleep` which eventually calls
`poll_oneoff` but `@bjorn3/browser_wasi_shim` does not implement it. So
we skip the test for now, but we will revisit it later once
bjorn3/browser_wasi_shim#88 is merged.
@bjorn3 bjorn3 merged commit 910395b into bjorn3:main Jun 22, 2025
1 check passed
@bjorn3
Copy link
Owner

bjorn3 commented Jun 22, 2025

Thanks!

@bjorn3
Copy link
Owner

bjorn3 commented Jun 22, 2025

Published as v0.4.2.

@kateinoigakukun kateinoigakukun deleted the katei/add-poll-oneoff branch June 22, 2025 14:40
@kateinoigakukun
Copy link
Contributor Author

Thanks!

kateinoigakukun added a commit to kateinoigakukun/wasi-libc that referenced this pull request Jun 22, 2025
This release includes a limited polyfill for `poll_oneoff` which is
necessary for the `pthread_cond` test to pass in the browser.
bjorn3/browser_wasi_shim#88
@ansemjo
Copy link
Contributor

ansemjo commented Jun 23, 2025

May I ask how this relates to #14? I've been using @igrep's patch for a while now to support time.Sleep in Go but I see that the implementations differ quite a bit. The implementation here assumes just a single subscription, which the other patch does not, I think. On the other hand, that patch doesn't actually sleep or busy-loop at all and I think the sleep only works because Go itself checks that the time has not actually passed yet and tries to sleep again.

@bjorn3
Copy link
Owner

bjorn3 commented Jun 23, 2025

This PR only adds support for sleeping for a certain amount of time. It doesn't do anything with other kinds of subscriptions. @igrep's patch should remain functional even with this PR. It just overwrites the implementation of this PR.

abrown pushed a commit to WebAssembly/wasi-libc that referenced this pull request Jun 25, 2025
Update @bjorn3/browser_wasi_shim to version 0.4.2. This release includes
a limited polyfill for `poll_oneoff`, which is necessary for the
`pthread_cond` test to pass in the browser.
bjorn3/browser_wasi_shim#88
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