• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSThread sleepUntilDate w/ dateWithTimeIntervalSinceNow and intervals < 1sec
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSThread sleepUntilDate w/ dateWithTimeIntervalSinceNow and intervals < 1sec


  • Subject: Re: NSThread sleepUntilDate w/ dateWithTimeIntervalSinceNow and intervals < 1sec
  • From: Pontus Ilbring <email@hidden>
  • Date: Sun, 30 Oct 2005 22:57:24 +0100

On 10/30/05, Nicolas Berloquin <email@hidden> wrote:
> Hello !
>
> I have a background thread that needs to loop every 25ms.
> After each loop, I calculate the time spent inside the loop, then call :
>
> [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: ]];
>
> with a value between ]0;25ms]. But I'm getting strange offsets in what
> should be a continuous heartbeat.
>
> The docs talk about :
> + (id)dateWithTimeIntervalSinceNow:(NSTimeInterval)seconds
>
> NSTimeInterval being a double, I assumed I could pass miliseconds,
> or even microseconds. Does it actually round the parameter to the
> nearest second?

It certainly doesn't round to whole seconds. Expecting accuracy to be
within ±1 ms would not be unreasonable.

By the way, why calculate the time it takes to execute the loop when
you could do this:

while (true)
{
        NSDate *sleepDate = [[NSDate alloc] initWithTimeIntervalSinceNow:0.025];
        NSLog(@"work");
        [NSThread sleepUntilDate:sleepDate];
        [sleepDate release];
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSThread sleepUntilDate w/ dateWithTimeIntervalSinceNow and intervals < 1sec (From: Nicolas Berloquin <email@hidden>)

  • Prev by Date: Re: IB not updating header file
  • Next by Date: Date/Time picker view
  • Previous by thread: NSThread sleepUntilDate w/ dateWithTimeIntervalSinceNow and intervals < 1sec
  • Next by thread: Date/Time picker view
  • Index(es):
    • Date
    • Thread