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

Shouldn't unix/sleep.c use clock_nanosleep (if available) instead of nanosleep? #7802

Open
vicuna opened this issue Jun 8, 2018 · 4 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link

commented Jun 8, 2018

Original bug ID: 7802
Reporter: berenger
Status: new
Resolution: open
Priority: normal
Severity: feature
Platform: unix-like
Category: standard library
Monitored by: @nojb

Bug description

If deemed useful, I can send a patch.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 8, 2018

Comment author: @nojb

What would be the benefit of switching to clock_nanosleep?

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 11, 2018

Comment author: berenger

Better precision in some specific cases.
Cf. man nanosleep:

   If a program that catches signals and uses nanosleep() receives signals
   at  a very high rate, then scheduling delays and rounding errors in the
   kernel's calculation of the sleep  interval  and  the  returned  remain
   value  mean  that  the remain value may steadily increase on successive
   restarts  of  the  nanosleep()  call.   To  avoid  such  problems,  use
   clock_nanosleep(2)  with the TIMER_ABSTIME flag to sleep to an absolute
   deadline.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 12, 2018

Comment author: @nojb

Thanks. Have you come across an actual situation where the current implementation is problematic or is this request about a potential problem?

Personally I am not familiar with the signal handling code, so I can't say whether this change is worth it or not, but feel free to open a PR if you would like to get wider feedback on this proposal.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 13, 2018

Comment author: berenger

I am worried about the potential problem.
As a C programmer, by reading the manpage, I would have used clock_nanosleep
instead of nanosleep (maybe it became available later).
I was reading the C implementation of unix_sleep in otherlibs/unix/sleep.c, which is called by Unix.sleepf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.