Re: Quitting an application
Sujith wrote: 1 * Init various GUI elements including the track treeview. 2 * Read the DB and append elements to the treeview. 3 * call gtk_main() and wait for events. What about: 1. Init various GUI elements including the track treeview. 2. Install a g_idle callback. 3. call gtk_main() and wait for events. 4. Read the DB and append elements to the treeview. (split DB read loop in subsequent g_idle iterations) 5. remove g_idle source when finished. Cheers, Andy ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Quitting an application
On Thu, Mar 27, 2008 at 08:01:40PM +0530, Sujith wrote: Hi, I am writing a music library manager and I have a small problem when terminating the application. On starting the app, I scan a DB and load the tracks into a treeview. When this is in progress, if the user closes the application, a segfault occurs because gtk_main_quit() has been called and the scanning function tries to access data structures that are no more. How do I synchronize between them ? This is a quite common problem in GUI design. How do you syncronize between a long job and a short fast one (as quitting). The first answer is that you should not do any long jobs. You should split the long work in small ones, and let every other job have the ability to run. Alternative you could make a coprocess to read the DB and when the work is done you get the result in one operation. Well - the real answer is - it could be difficult. You might turn to some syncronization mechanism or maybee threads... -- Göran Hasse Göran Hasse email: [EMAIL PROTECTED] Tel: 08-6949270 Raditex AB http://www.raditex.se Planiavägen 15, 1tr Mob: 070-5530148 131 34 NACKA, SWEDEN OrgNr: 556240-0589 VAT: SE556240058901 -- ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Quitting an application
G Hasse writes: This is a quite common problem in GUI design. How do you syncronize between a long job and a short fast one (as quitting). The first answer is that you should not do any long jobs. You should split the long work in small ones, and let every other job have the ability to run. Alternative you could make a coprocess to read the DB and when the work is done you get the result in one operation. Well - the real answer is - it could be difficult. You might turn to some syncronization mechanism or maybee threads... Thanks. I guess I have to rethink my design then. :) Sujith ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Quitting an application
Gabriele Greco writes: Intercept the delete_event or modify the callback where you do the gtk_main_quit() and insert there some thread sync code. You should take care also when you add the rows to your Tree/ListStore if you do that directly from the thread that scans the db. I suppose there is a thread since if there isn't one when you quit the main loop nothing can crash it (except something you call after gtk_main()) :) I don't have a separate thread that does the DB scanning. The sequence of operations is something like this: 1 * Init various GUI elements including the track treeview. 2 * Read the DB and append elements to the treeview. 3 * call gtk_main() and wait for events. Now, if the user quits between 2 and 3, it becomes an issue because gtk_main() hasn't been called yet and I can't check for the main loop. If gtk_main() has been invoked, I can check for the existence of the mainloop like this: while(gtk_events_pending()) if (gtk_main_iteration_do(FALSE)) return; Is spawning a thread and cooking up some simple synchronization scheme the only way to quit gracefully ? thanks, Sujith ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Quitting an application
Sujith wrote: Gabriele Greco writes: Intercept the delete_event or modify the callback where you do the gtk_main_quit() and insert there some thread sync code. You should take care also when you add the rows to your Tree/ListStore if you do that directly from the thread that scans the db. I suppose there is a thread since if there isn't one when you quit the main loop nothing can crash it (except something you call after gtk_main()) :) I don't have a separate thread that does the DB scanning. The sequence of operations is something like this: 1 * Init various GUI elements including the track treeview. 2 * Read the DB and append elements to the treeview. 3 * call gtk_main() and wait for events. Now, if the user quits between 2 and 3, it becomes an issue because gtk_main() hasn't been called yet and I can't check for the main loop. If gtk_main() has been invoked, I can check for the existence of the mainloop like this: while(gtk_events_pending()) if (gtk_main_iteration_do(FALSE)) return; I have not checked, but maybe gtk_main_leve() returns 0 if gtk_main() has not been called yet? If that would be of any help. Is spawning a thread and cooking up some simple synchronization scheme the only way to quit gracefully ? thanks, Sujith ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Quitting an application
Hi, I am writing a music library manager and I have a small problem when terminating the application. On starting the app, I scan a DB and load the tracks into a treeview. When this is in progress, if the user closes the application, a segfault occurs because gtk_main_quit() has been called and the scanning function tries to access data structures that are no more. How do I synchronize between them ? Any help is appreciated. Sujith ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Quitting an application
I am writing a music library manager and I have a small problem when terminating the application. On starting the app, I scan a DB and load the tracks into a treeview. When this is in progress, if the user closes the application, a segfault occurs because gtk_main_quit() has been called and the scanning function tries to access data structures that are no more. How do I synchronize between them ? Intercept the delete_event or modify the callback where you do the gtk_main_quit() and insert there some thread sync code. You should take care also when you add the rows to your Tree/ListStore if you do that directly from the thread that scans the db. I suppose there is a thread since if there isn't one when you quit the main loop nothing can crash it (except something you call after gtk_main()) :) -- Bye, Gabry ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list