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

Enhance / redesign the time module #2153

Closed
boggle opened this issue Apr 7, 2012 · 9 comments
Closed

Enhance / redesign the time module #2153

boggle opened this issue Apr 7, 2012 · 9 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@boggle
Copy link
Contributor

boggle commented Apr 7, 2012

  • nanosleep (difficult on windows but doable with 100 ns solution using win32 API)
  • function for the normalization of timespec values
  • substraction, addition, comparison functions are needed
  • hash
  • support for printing times in fmt
  • serialization helpers would be nice, too
@boggle
Copy link
Contributor Author

boggle commented Apr 7, 2012

http://www.c-plusplus.de/forum/43364

(win32 nanosleep)

@brson
Copy link
Contributor

brson commented Apr 8, 2012

I don't know if we want to encourage sleep functions that actually put the thread to sleep (though obviously they are useful for some purposes). Sleeping should generally just block the task and let the runtime continue to schedule other tasks. Timers is one of the first things I was planning on implementing with libuv.

@boggle
Copy link
Contributor Author

boggle commented Apr 8, 2012

Ah, I didn't consider doing timers via libuv. Just thought that we should have a high resolution sleep function that matches to the timespec type. I was thinking about all things in the context of recv with timeout. Keeping this in mind, whatever sleep/timer function will be used maybe should go into the runtime for consistency of implementation.

Regarding a blocking sleep, a frequent use case I had in golang was in tasks that are locked onto a fixed thread due to C interop requirements (libzeromq bindings).

@catamorphism
Copy link
Contributor

Nominating to change milestone to feature-complete.

@graydon
Copy link
Contributor

graydon commented Jul 11, 2013

time module is kinda ad-hoc at this point, needs more principled (re)design

@graydon
Copy link
Contributor

graydon commented Jul 18, 2013

accepted for backwards-compatible milestone

@huonw
Copy link
Member

huonw commented Jan 3, 2014

bors added a commit that referenced this issue Aug 19, 2014
This implements `Add` and `Sub` for `Timespec`, which enables `Timespec` to be used as a time span. For example:

```rust
let begin = get_time();
// Do some stuff.
let end = get_time();
let delta = end - begin;
println!("Doing stuff took {}.{:09d} seconds.", delta.sec, delta.nsec);
```
This resolves one of the points mentioned in #2153.
@gsingh93
Copy link
Contributor

This should probably be moved to https://github.com/rust-lang/time, unless we want to add any of these features to std::time.

@steveklabnik
Copy link
Member

Agreed.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
with permissive-provenance set, we already treat ptr::invalid correctly

(same for strict provenance, but there it is not surprising)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

8 participants