-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking Issue for thread::sleep_until #113752
Comments
The clockEach of the three options has its downsides:
I think the clock question is not constrained to There we can figure out:
I would love to write a Pre-Rfc for such an API if we decide to go that route. Type of the deadline argumentI am in favor of using If we decide to support both we need to figure out if we want two functions or |
Add implementation for thread::sleep_until - Feature gate is `thread::sleep_until` - Tracking issue is: rust-lang#113752 - APC: rust-lang/libs-team#237
Are there OS APIs that support sleeping to a deadline? The current implementation will have large tail latencies: let now = Instant::now();
if let Some(delay) = deadline.checked_duration_since(now) {
// Context switch here. Oops, now we'll end up arbitrarily blowing past the deadline
sleep(delay);
} |
There's |
Wall-time based synchronization/execution of events. E.g. if something is supposed to run in a cronjob-like fashion. Or a distributed protocol that says "nodes try to rendezvous every 5 minutes, at the start of a minute divisible by 5, UTC". |
Thanks for bringing this up! We can freely use that on Linux, the minimum kernel version current Rust supports includes it. I would have to check it for POSIX. Even if that does not pan out we should 'specialize' this method on Linux. Before we go down that road I would like to nail down the API. To answer that we must know whether we want a Clock API in Rust. That however is better addressed in a separate proposal. I am more then willing to write that up however I would like to estimate interest first. I am not sure how to proceed there, an option would be to create a crate that adds a clock API to std-lib functions/types where appropriate (using traits). Then look at how popular that gets over time. (taking care to prevent an itertools situation). Another easier path would be a users forum post or github code search. |
You could also look at prior art in other languages and frequently used libraries. E.g. C++ has it std::chrono. |
macOS and the other Apple platforms don't have it, even on the newest versions. |
There seems to be a function called |
Replying to @neachdainn who commented on the RFC
It's temporary, the idea was to see if we could take the clock choice further and introduce a clock API. That would allow use of clocks that are not supported on each platform (such as clock I am gonna paraphrase your use case here, I think it is an important one:
As it is critical to the above use case I will open a PR to switch over the placeholder implementation for Linux to use Then I will see if we can get the same behavior on the other operation systems. |
This is a tracking comment tracking the effort to specialize/optimizing the Possible/In progress:
Seems impossible for now
Hard
Ignored
|
@dvdsk Clock Nano sleep is available in libc for VxWorks. |
Feature gate:
#![feature(sleep_until)]
This is a tracking issue for the
thread::sleep_until
method. It pauses thecurrent thread until a given deadline.
Public API
Steps / History
Unresolved Questions
thread::sleep
, something different or passedin by the user?
Instant
, aSystemTime
or do we support both?Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: