Re: How to handle long I/O operations



On Tue, 14 Aug 2001 18:10:17 +0200, Jean-Christophe Berthon said:

Hello,
 
 First a big thanks to Markus, Tara and Luciano for their help. It helped me
 understand better the timeout, idle and "threads" in Gtk.
 But like Markus mentioned it, it will be hard for me to use the timeout as I
 have no clue of how long the computation will take (it's kind of heavy
 mathematical computation involving matrix and "3D" representation of
 thousands of points in a geodesic origin, it can take a few hours up to a
 few days! Depending on the precision the user ask, and how many points are
 involved) So if my calculation exceed the timeout period I guess I will got
 a crash (if it behaves like in a real-time environment) So I guess the
 gtk_idle_add looks more appropriate.
 And thanks Tara for the warning for the "thread safe" problem that might
 occur while using gtk_main_iteration.


We try our best. :)

There's a few things I wanted to PS to what was talked about
earlier.

I put our design to the test again and found some issues.

I recommend using GTK+ timeouts and when you use them I
recommend that you design your main GTK+ job management handler
as follows (it's quite efficient and works for long calculations):


guint toid;     /* Might want to make this a local and pass it around. */

gint manage_tocb(gpointer data)
{
        /* Manage jobs here. */





        /* Schedual another timeout for this same function. */
        toid = gtk_timeout_add(
            50,
            (GtkFunction)manage_tocb,
            NULL
        );
        /* Return FALSE so this function is not called again for
         * the same timeout id. But don't worry, we already schedualed
         * a NEW timeout id to call this function again in 50 ms.
         */
        return(FALSE);
}

int main(int argc, char *argv[])
{
        /* ... */

        toid = gtk_timeout_add(
            50,
            (GtkFunction)manage_tocb,
            NULL
        );

        /* ... */
}



-- 
--
Sincerely,                  ,"-_                         \|/
-Capt. Taura M.             ,   O=__                    --X--
.__                          ,_JNMNNEO=_                 /|\
OMNOUMmnne.                  {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn.               'LONMMMMNNEEEOOO=.__..,,..
UUOOEUUOOOOOOOObe              '"=OMMMMWNEEEOOOOO,"=OEEEOO=,._
OOUUUIEEIOONNOIUbe.                "7OMMMMNNNNNWWEEEEOOOOOO"   "'.
EEBNNMMMNWNWWEEIMMNe.             __  7EMMMNNNNNWWWEEEEEEEOO.     " .
NNMMMMWWWMMMWEINMMMNn            "=BBEEEEMMMMMMMMNNNWWWEEOOOOO=._     .
                  http://furry.ao.net/~learfox/






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