Re: Stalls in idle loop



Nick Matsakis <matsakis@merl.com> wrote:

>I'm having a problem with a GTK-based application.  Simply, I have written
>a program which makes extensive use of an idle function, installed with
>gtk_idle_add().  Periodically, for no apparent reason, the GTK main loop
>ceases to run the idle function. Moving the mouse, pressing a key on the
>keyboard, or otherwise sending an event to the program causes the idle
>loop to be run again.  My questions, therefore, are:
>

 Well, Using gtk_idle_*() is a little tricky. It works this way. The
function(ie. callback) you pass to it is called only once when the main
function becomes idle. No matter how long it remains idle, your function will
be called only once. Next time when the main function becomes idle again,
then again your function will be called. It is not this way that as long as
the main function is idle, your function will be called continously (of
course, one after another). In short, your function will be called only
once for each session of idle-ism (eh).

  This is the reason why moving the mouse, pressing a key on the
keyboard, or otherwise sending an event to the program causes the idle
loop to be run again. Basically, what your are doing in the above action
is generating different sessions of idle-ism and your funcion will be
executed once for each session.
 
  Moreover, the main function will get control only when your function has
returned. So, your call-on-idle function should not take long time to return.
Otherwise, your application will become jerky.

>1) Is this a known problem? 

I don't think this a problem, beacause it is the inherent property of the
implementation. Gtk has no idea how many times it should call your function
when it becomes idle. That's why (I suppose) it is called only once :-).

>2) Is there an elegant solution? 

>3) If not, is there an inelegant solution?  My one thought is to send some
>  sort of "null event" at the end of the idle loop, ensuring that there is
>  always an event in the queue whenever the idle loop ends.  I don't know
>  why that might work, but it seems to me that if moving the mouse fixes
>  the problem, this might too. 

  Your idea may work. But that's not the best idea. Do something else.

  If your idea of using too many idle functions is to improve the performance
of your application (by utilizing the idle period) or to perform some
background jobs, then make sure that the main function gets its control as
soon as it needs. otherwise, you will be annoying the users by making them
feel the background jobs :).

  Whatever I have stated above is not garranteed to be 100% correct, because
it is not from some literal source. It is, rather, what I've exeperienced
while doing some stuff with the gtk_idle_* functions. Any correction is most
welcome.


regards
-naba


__________________________________________________
Do You Yahoo!?
Yahoo! Mail  Free email you can access from anywhere!
http://mail.yahoo.com/




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