GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Apr 17, 2014 7:15 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: glib timer question
PostPosted: Tue Jun 19, 2012 7:48 am 
Offline
Familiar Face

Joined: Tue Dec 20, 2011 3:27 pm
Posts: 14
hi all,
sorry if glib is a bit out of topic,

I am using g_timeout_add, and wandering what happen if the callback takes a time greater than the interval.

Reading the doc i find:
Quote:
Note that timeout functions may be delayed, due to the processing of other event sources. Thus they should not be relied on for precise timing. After each call to the timeout function, the time of the next timeout is recalculated based on the current time and the given interval (it does not try to 'catch up' time lost in delays).


Seems that the interval is recalculated, but not clear how. For example what happen if interval is 1 and my function takes 2 ?

Thanks


Top
 Profile  
 
 Post subject: Re: glib timer question
PostPosted: Tue Jun 19, 2012 7:52 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
Hi,

This is on topic.

With g_timeout_add() when you add a time out your signal may be received some time after your requested time. To take a case which is probably unlikely to happen, but is possible. Say you requested a time out of 1 second, it is possible that you receive the signal 1.5 seconds latter. That is a 50% error. Note this is unlikely to happen unless you have done something very wrong else where in your code.

If you are having recurring time outs of 1 second you could have

- Time out 1.1 second
- Time in your call back
- Time out 1.4 second
- Time in your call back
- Time out 1 second
- Time in your call back
- Time out 1.1 second
- Time in your call back
- Time out 1.2 second
- Etc. etc.

_________________
E.


Top
 Profile  
 
 Post subject: Re: glib timer question
PostPosted: Tue Jun 19, 2012 9:39 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 176
Location: USA
Interesting topic, sorry I don't mean to hijack your thread hear Angelo. Errol, so there's no way to ensure accurate reoccurring time outs? If not what's the best way to reduce the margin of error?


Last edited by zerohour on Wed Jun 20, 2012 6:33 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: glib timer question
PostPosted: Wed Jun 20, 2012 6:25 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
g_timeout_add has never been intended to be used for accurate timing, due to it being fairly generic. Delays in producing the signal can be caused by many situations. These include the load on the CPU by other processes and other threads, processing of other signals, poor quality of coding in other signals.

There are many ways to improve timing. This depends on your situation/operating system and what you need to do and how accurate you really need to have it.

One way to improve the situation is to set the priority of the signal handler higher such as G_PRIORITY_HIGH. This will make sure that this signal is processed before any other, but can not help if another signal is blocking already in a call back that is taking a long time.

Another possibility is to having your timings handled in another thread if what you need done is not GTK dependent or use POSIX signals.

Note in my thought example, these timings are just very bad case conditions and your timings will probably be much better. But things like this can happen if you have poor code in your other call-backs.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group