Re: How to create precise timeouts?



Nils Rennebarth <nils@ipe.uni-stuttgart.de> writes:

> From reading the description of g_timeout_add, it seems that if I
> call
>     g_timeout_add(100,function,NULL)
> and function itself takes 80ms to complete, this will end up in function
> being started every 180ms. Is this right?
> 
> What I want is to have it beeing called about every 100ms, maybe 10ms
> earlier or later but 10 times a second in the average. How do I do this
> (short of resorting to the setitimer system call)?

Well, what you should probably do is call gettimeofday, and figure
out the time remaining to the next time you want your timeout
to be called. 

You can then add a new timeout with that duration, and then return
FALSE from the old timeout so that it won't be invoked again.

Regards,
                                        Owen 

(Note you'll never get "precision" with a GTK+ timeout - things
like processing events can delay your timeout arbitrarily. But
with this method your timeout won't drift.)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]