Re: How to handle long I/O operations
- From: Markus Lausser <sgop users sourceforge net>
- To: gtk-app-devel-list gnome org
- Subject: Re: How to handle long I/O operations
- Date: Mon, 13 Aug 2001 21:00:58 +0200
On Mon, Aug 13, 2001 at 05:07:55PM +0200 Jean-Christophe Berthon wrote:
Hy,
OK, so each time a callback is running, no others can be fired at the same
time as the one running "hold" the main loop. If I'm wrong tell me.
it is possible by the user, but gtk cant do it.
But you're speaking of the function gtk_idle_add. If I understand it
correctly : if I link my heavy function to this function, each time there is
no event to treat, the function is running. So to implement it I should do
something like :
- in the callback of the "start calculus"
idTimeout = gtk_timeout_add(500, function_show_activity,
(gpointer)NULL);
idIdle = gtk_idle_add(function_calculating, struct_job);
correct.
- in function_calculating
/* My heavy calculus */
/* ... */
/* calculus finished */
gtk_idle_remove(idIdle);
gtk_timeout_remove(idTimeout);
Will it work as I'm expecting (excuting the calculus while showing an
activity bar and the calculus is execute only once!) ?
no. you forgot to call the gtk_main_iteration() manually.
The calculation is executes once, yes. But while running there will no other
callback be executed (no timeout function, even no GUI update, your app will
be frozen until you have finished the calculation).
You have to call the gtk_main_iteration() in your calc function
as described in my last post.
Isn't it a
performance issue also? As the calculus is rather huge and with complicate
data, it has to be working efficiently. By doing it in "background", is it
going to be much slower (did you have any experience with that in fact?)?
The calculation isnt done in the "background", it is in the foreground. The
only difference to a "normal" program is, that you have to take care of all
that stuff that has to be done during the calculation.
And last question, how it is working? Because let say Gtk has nothing to do
(so he is idle) then the function_calculating is launch, but then the
timeout event trigger! So will it stop the function_calculating and execute
the timeout callback and then relaunch the idle function, or will it "hold"
the execution of the idle function while processing the timeout callback?
The idle function is quite useless here if you want to do this calculation
only once. Just fire up the calculation and insert the gtk_main_iteration()
seomwhere there in a loop.
What gtk does is: your application is (after gtk_main();) always in the
gtk main loop. From there it processes all the events by calling the
according callback functions (i think, one per loop, but i dont know).
If it returns from one callback function, it does another iteration in the
main loop.
Markus.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]