pal/hermit: correctly round up microseconds in Thread::sleep by mkroening · Pull Request #129588 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation8 Commits2 Checks6 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

mkroening

@mkroening

Signed-off-by: Martin Kröning martin.kroening@eonerc.rwth-aachen.de

@rustbot rustbot added O-hermit

Operating System: Hermit

S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

labels

Aug 25, 2024

@workingjubilee

@workingjubilee

I assume hermit here is assessed as not having to do the "repeatedly call the underlying sleep fn" thing because it has 64-bit usleep?

What if Duration::as_micros returns a u128 greater than u64::MAX?

@workingjubilee

granted, perhaps sleeping accuracy over... uh, would it be... 500,000 years?... is not a concern.

@workingjubilee

...actually, it IS a little bit of a concern: if someone inputs a really absurd Duration, the as conversion is not saturating, it is truncating-to-bits, thus someone can request to sleep until an Age has came and went but actually wake up 0 seconds later. We should first at least use u128::min(u64::MAX as u128, micros)

@workingjubilee

That is still only relevant to vampires writing Rust code to manage their wakeup alarms for torpor, but can you imagine how cranky someone would be if they woke up a hundred thousand years early?

Probably we should respec Duration in such a way that people don't have to worry about this absurdity, or introduce a new type and make thread::sleep take a generic, but until then...

@mkroening

Signed-off-by: Martin Kröning martin.kroening@eonerc.rwth-aachen.de

@mkroening

Thanks for the quick review!

I pushed a commit to saturate the conversion. :)

@workingjubilee

Cool, thanks!

@bors r+ rollup

@bors

📌 Commit edeefc5 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Aug 26, 2024

bors added a commit to rust-lang-ci/rust that referenced this pull request

Aug 26, 2024

@bors

…iaskrgr

Rollup of 7 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Aug 26, 2024

@bors

…iaskrgr

Rollup of 7 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Aug 26, 2024

@rust-timer

Rollup merge of rust-lang#129588 - hermit-os:sleep-micros, r=workingjubilee

pal/hermit: correctly round up microseconds in Thread::sleep

This fixes the Hermit-related part of rust-lang#129212 and thus the whole issue, since ESP-IDF is already fixed, as far as I understand.

Fixes rust-lang#129212

r? @workingjubilee

CC: @stlankes

Labels

O-hermit

Operating System: Hermit

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.