Hi. I'm considering using OpenGCD in a project, so I created a small Android app to try it out.
In doing so, I ran into a possible problem with timers. Using the code below, I set a timer to go off every 1 second. But the timer is not as precise as I'd expected. Sometimes it's late by several tenths of a second. Any idea why that would be?
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), NSEC_PER_SEC, 0);
dispatch_source_set_event_handler(timer, ^{
struct timespec res;
clock_gettime(CLOCK_REALTIME, &res);
double time = res.tv_sec + (double) res.tv_nsec / 1e9;
__android_log_print(ANDROID_LOG_INFO,"test","%f\n", time);
});
dispatch_resume(timer);
A more general question — Would you consider the 0.2 release stable, or more of a work in progress? (Is http://sourceforge.net/p/opengcd/wiki/Android/ up to date? I'm guessing not, as it predates the 0.1 release.) Is OpenGCD the most mature available port of libdispatch to Android?
Thanks,
Jaymie Strecker
|