I have a background application which requires to send a keep-alive to another process every 1.5 seconds. Everything works smoothly in OSX 10.7 and 10.8, but under OSX 10.9 many keep-alive notifications are missed, sometime up to 3. Usually everything works fine for the first 3 or 4 minutes then problems start to occur.
After further inspection, it seems that OSX Mavericks "Timer Coalescing" feature would be responsible for making the decision of extending the requested 1.5 seconds up to 4.0 seconds.
Is there any way to indicate in a NSThread not to coalesce? Or at the very least to indicate the maximum coalescing variations allowed?
See code below for reference:
+(void)keepAliveThread
{
@autoreleasepool {
void (^keepAlive)() = ^ (){
// (snipped!) do something...
};
dispatch_queue_t mainQueue = dispatch_get_main_queue();
while( [NSThread currentThread].isCancelled == NO )
{
@autoreleasepool {
dispatch_async(mainQueue, keepAlive);
[NSThread sleepForTimeInterval:1.5];
}
}
}
}