Re: How to handle long I/O operations



On Mon, Aug 13, 2001 at 11:18:56AM +0200 Jean-Christophe Berthon wrote:

            Hello,

    I'm interested in this behaviour also as we will have a callback which
call a really long calculus (can take hours) And it would be interessant to
see a progress or activity bar. And as we will need to function under many
different Linux and UNIX, we cannot use pthreads (I've heard that they were
suffering some portablilty issues).

    So your solution is interesting me. But I didn't really understood it
(I'm quite new to Gtk). So one first question that might enlight me : When
you create a timeout (using gtk_timeout_add) with a period of a second for
example, if another callback which will take let say about a minute is
fired. Does the callback attached to the timeout is fired still every second
(while the other is computing at the same time) or does it wait to be fired
until the other callback ends?

No. There is a main loop in the GTK implementation that takes care of all
events that are present (GUI events, Timeouts, read/writeable
filedescriptors, etc. and last the idle functions). If you do a long
calculation in a timeout function then the gtk main loop is not called, no
other user defined functions are called nor is the GUI updated. You can force
it by calling single main loop iterations manually in your calc function
from time to time (maybe in a loop there):

  while (gtk_events_pending())
    gtk_main_iteration();

If you have also have added a timeout function that updates your progress bar
then your problem should be solved.
"while (gtk_events_pending()) {};" could be dangerous, because it could also
block your calc function, if there is always a pending event (e.g. a idle
function; dont know whether this is a "pending" event, but i am afraid it
is). So a "if (gtk_events_pending()) {};" may be better.


    That will be all for the moment, once I understand this part, I might
have other question. We will see :-)

Feel free:)

Markus




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