Re: execution of timers from other callbacks




On Dec 17, 2008, at 12:00 PM, zentara wrote:

Hi,
I saw something on the gtk2-c list that got me thinking. :-)

In the following code, a timer is placed in a button callback,
but without a "non-blocking-delay" or a forced-loop-update
in the for loop, the timer dosn't run until the button callback
returns......even with very large numbers in the for loop.

So is this a rule? That timeouts and idle_adds won't be scheduled
until the callback they are in finishes, or you force the
eventloop to check itself?
Where is this documented? Or is it suposed to be obvious? :-)

Here's the call flow:

gtk_main()
   g_main_loop_run()
      g_main_context_dispatch()
         timeout callback
            timeout add
            spin in a loop

Since you didn't return from the timeout callback, the main loop didn't run, and therefore your timeout doesn't fire. You must

a) return from the callback, which implies

i. break your work into chunks and handle each chunk in an idle callback ii. fork a subprocess to do the work, with pipes for communication and all that

b) use a new main loop, as in your non_blocking_delay() function, which implies that you are simply waiting for something

c) eat events manually, which implies you're doing real work, and if it's going to take a while, you don't want to do it this way


--
elysse:  You dance better than some.
me:  "Some" what?
elysse:  Some asparagus.





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