Re: Possible bug with nanosleep()?
site_archiver@lists.apple.com Delivered-To: Darwin-kernel@lists.apple.com User-agent: Alpine 1.00 (DEB 882 2007-12-20) Hi Michael, On Tue, 2 Mar 2010, Michael Smith wrote: I think you might be a bit confused about how time and timing works. Cheers, Chris. -- _ ___ __ _ / __/ / ,__(_)_ | Chris Wilson <0000 at qwirx.com> - Cambs UK | / (_/ ,\/ _/ /_ \ | Security/C/C++/Java/Perl/SQL/HTML Developer | \ _/_/_/_//_/___/ | We are GNU-free your mind-and your software | _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... 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. If all you care about is whether at least the requested time has elapsed, you should be calling gettimeofday() once nanosleep returns. Yes, you're right, I should do that and ignore the remaining time returned by nanosleep(). But I still think that the remaining time returned is wrong, and that there's a bug in the nanosleep implementation on OSX. 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. I agree, this is not a real-time application. What I meant is that I'd really prefer it if my nanosleep was not interrupted by signals, and if it is, I just want to sleep again until the appointed time. I don't want to mess about with signal masks as nanosleep might (now or in future) be internally implemented using signals on some platforms (I've seen this with sleep()). This email sent to site_archiver@lists.apple.com
participants (1)
-
Chris Wilson