Re: Possible bug with nanosleep()?
Re: Possible bug with nanosleep()?
- Subject: Re: Possible bug with nanosleep()?
- From: Michael Smith <email@hidden>
- Date: Tue, 2 Mar 2010 00:48:08 -0800
On Mar 2, 2010, at 12:26 AM, Chris Wilson wrote: Hi Terry and all, This looks suspiciously like code one would use to implement a polling loop. That's generally a mistake.
I don't think it's a polling loop, I just want to damn well be sure that I sleep for the time requested, regardless of interruption. This function is used in timing-sensitive unit tests.
I think you might be a bit confused about how time and timing works.
If all you care about is whether at least the requested time has elapsed, you should be calling gettimeofday() once nanosleep returns. I'm not interested at all in signals in this code, I wish they wouldn't happen, I just want to sleep for the appointed time and nothing else.
You can't do that; other threads may run, resulting in you not executing for considerably longer. You can ensure that you sleep for no less than the requested time by adjusting your signal mask appropriately, or looping with a call to gettimeofday to ensure that you have not been woken early.
You can't guarantee that your thread will suspend and resume execution at a precise time.
= Mike
-- Excellence in any department can be attained only by the labor of a lifetime; it is not to be purchased at a lesser price -- Samuel Johnson
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden