Re: Multi-threaded UI Freezes on GDK Call
Emmanuele Bassi wrote: On Tue, 2007-12-18 at 20:37 -0500, Michael McCann wrote: Yes, I've already tried that, to no avail. My code basically only consists of: gdk_screen_get_default(): Get the default screen gdk_screen_get_root_window(): Get the root window gdk_pixbuf_get_from_drawable(): Get a pixbuf from the entire screen gdk_pixbuf_save_to_bufferv(): Save the pixbuf to a buffer. taking a screenshot of the root window takes a considerable amount of time, depending on the size of the screen and the amount of windows on it. gnome-screenshot forks in the background to avoid blocking the UI; since GDK cannot be called from multiple threads, forking is the only option you have. ciao, Emmanuele. Thanks for all of the suggestions. I'll try out the fork method you mentioned. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
On Tue, 18 Dec 2007 22:52:23 +0100 G Hasse [EMAIL PROTECTED] wrote: The wrong thing is trying to do threads! Why Why Why are all people doing this thread programing! I am convinced that with a propper design of your application, maybe in several processe, you don't need threads and your problem will go away... No, threads are not the problem. Not keeping ALL GUI-related things in ONE thread is the problem. I may have been missing the point, but it seems that this is the core of the OP's troubles. The problem with threads is that few beginners understand what they actually are. --D. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
On Tue, 2007-12-18 at 20:37 -0500, Michael McCann wrote: Yes, I've already tried that, to no avail. My code basically only consists of: gdk_screen_get_default(): Get the default screen gdk_screen_get_root_window(): Get the root window gdk_pixbuf_get_from_drawable(): Get a pixbuf from the entire screen gdk_pixbuf_save_to_bufferv(): Save the pixbuf to a buffer. taking a screenshot of the root window takes a considerable amount of time, depending on the size of the screen and the amount of windows on it. gnome-screenshot forks in the background to avoid blocking the UI; since GDK cannot be called from multiple threads, forking is the only option you have. ciao, Emmanuele. -- Emmanuele Bassi, W: http://www.emmanuelebassi.net B: http://log.emmanuelebassi.net ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Multi-threaded UI Freezes on GDK Call
I've got a multithreaded GTK application. One thread runs gtk_main(): gtk_threads_enter(); gtk_main(); gtk_threads_leave(); The other thread is an infinite loop that sleeps for one second on each loop. Every x seconds, the infinite loop calls a function, which makes some GDK calls. At the beginning of this function, gdk_threads_enter() is called; at the end, gdk_flush() and gdk_threads_leave() is called. Whenever this function is called, the UI freezes and CPU usage jumps to 100% for about one second (no other applications freeze, of course). I've tried calling gdk_threads_leave()/enter() before and after each GDK call to no avail. I run g_thread_init() and gdk_threads_init() at the beginning of my program. In the function, gdk_screen_get_default(), gdk_screen_get_root_window(), gdk_pixbuf_get_from_drawable(), and gdk_pixbuf_save_to_bufferv() are called. I'm using NetBSD on a P4 1.2GHz. What am I doing wrong? I've asked this question on IRC (irc.gnome.org, #gtk+) but noone seems to know the problem. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
On Tue, Dec 18, 2007 at 04:45:50PM -0500, Michael McCann wrote: I've got a multithreaded GTK application. One thread runs gtk_main(): gtk_threads_enter(); gtk_main(); gtk_threads_leave(); The other thread is an infinite loop that sleeps for one second on each loop. Every x seconds, the infinite loop calls a function, which makes some GDK calls. At the beginning of this function, gdk_threads_enter() is called; at the end, gdk_flush() and gdk_threads_leave() is called. Whenever this function is called, the UI freezes and CPU usage jumps to 100% for about one second (no other applications freeze, of course). I've tried calling gdk_threads_leave()/enter() before and after each GDK call to no avail. I run g_thread_init() and gdk_threads_init() at the beginning of my program. In the function, gdk_screen_get_default(), gdk_screen_get_root_window(), gdk_pixbuf_get_from_drawable(), and gdk_pixbuf_save_to_bufferv() are called. I'm using NetBSD on a P4 1.2GHz. What am I doing wrong? I've asked this question on IRC (irc.gnome.org, #gtk+) but noone seems to know the problem. The wrong thing is trying to do threads! Why Why Why are all people doing this thread programing! I am convinced that with a propper design of your application, maybe in several processe, you don't need threads and your problem will go away... ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- Göran Hasse Göran Hasseemail: [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: Multi-threaded UI Freezes on GDK Call
On Tue, 2007-12-18 at 16:45 -0500, Michael McCann wrote: I've got a multithreaded GTK application. One thread runs gtk_main(): gtk_threads_enter(); gtk_main(); gtk_threads_leave(); I assume you meant g_threads_init(); gdk_threads_init(); gtk_init(); gdk_threads_enter(); gtk_main(); gdk_threads_leave(); right? The other thread is an infinite loop that sleeps for one second on each loop. Every x seconds, the infinite loop calls a function, which makes some GDK calls. At the beginning of this function, gdk_threads_enter() is called; at the end, gdk_flush() and gdk_threads_leave() is called. Whenever this function is called, the UI freezes and CPU usage jumps to 100% for about one second (no other applications freeze, of course). I've tried calling gdk_threads_leave()/enter() before and after each GDK call to no avail. I run g_thread_init() and gdk_threads_init() at the beginning of my program. In the function, gdk_screen_get_default(), gdk_screen_get_root_window(), gdk_pixbuf_get_from_drawable(), and gdk_pixbuf_save_to_bufferv() are called. I'm using NetBSD on a P4 1.2GHz. What am I doing wrong? I've asked this question on IRC (irc.gnome.org, #gtk+) but noone seems to know the problem. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- Michael R. Head [EMAIL PROTECTED] http://www.suppressingfire.org/~burner/ http://suppressingfire.livejournal.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
On Tue, 2007-12-18 at 17:14 -0500, Michael R. Head wrote: On Tue, 2007-12-18 at 16:45 -0500, Michael McCann wrote: I've got a multithreaded GTK application. One thread runs gtk_main(): gtk_threads_enter(); gtk_main(); gtk_threads_leave(); I assume you meant g_threads_init(); gdk_threads_init(); gtk_init(); gdk_threads_enter(); gtk_main(); gdk_threads_leave(); right? The other thread is an infinite loop that sleeps for one second on each loop. Every x seconds, the infinite loop calls a function, which makes some GDK calls. At the beginning of this function, gdk_threads_enter() is called; at the end, gdk_flush() and gdk_threads_leave() is called. Whenever this function is called, the UI freezes and CPU usage jumps to 100% for about one second (no other applications freeze, of course). I've tried calling gdk_threads_leave()/enter() before and after each GDK call to no avail. I run g_thread_init() and gdk_threads_init() at the beginning of my program. Does your special function take time to do its job? If so, then that would be why. For example: ... while(1) { gdk_threads_enter(); sleep(1) gdk_threads_leave(); sleep(10) }; ... you'd freeze your app for a second every 10 seconds. In the function, gdk_screen_get_default(), gdk_screen_get_root_window(), gdk_pixbuf_get_from_drawable(), and gdk_pixbuf_save_to_bufferv() are called. I'm using NetBSD on a P4 1.2GHz. What am I doing wrong? I've asked this question on IRC (irc.gnome.org, #gtk+) but noone seems to know the problem. ___ -- Michael R. Head [EMAIL PROTECTED] http://www.suppressingfire.org/~burner/ http://suppressingfire.livejournal.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
Michael R. Head wrote: On Tue, 2007-12-18 at 17:14 -0500, Michael R. Head wrote: I assume you meant g_threads_init(); gdk_threads_init(); gtk_init(); gdk_threads_enter(); gtk_main(); gdk_threads_leave(); right? Yes, that is correct. :) Does your special function take time to do its job? If so, then that would be why. For example: ... while(1) { gdk_threads_enter(); sleep(1) gdk_threads_leave(); sleep(10) }; ... you'd freeze your app for a second every 10 seconds. Ahh, ok. How else can I accomplish my goal, then? I need to give GTK the lock, as I'm calling GDK from another function not in the main GTK loop. I tried leaving out gdk_threads_enter()/leave() in the CPU-intensive function, but X gives me errors. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
Michael McCann wrote: Michael R. Head wrote: On Tue, 2007-12-18 at 17:14 -0500, Michael R. Head wrote: I assume you meant g_threads_init(); gdk_threads_init(); gtk_init(); gdk_threads_enter(); gtk_main(); gdk_threads_leave(); right? Yes, that is correct. :) Does your special function take time to do its job? If so, then that would be why. For example: ... while(1) { gdk_threads_enter(); sleep(1) gdk_threads_leave(); sleep(10) }; ... you'd freeze your app for a second every 10 seconds. Ahh, ok. How else can I accomplish my goal, then? I need to give GTK the Which goal? Describe what your app is supposed to do. lock, as I'm calling GDK from another function not in the main GTK loop. I tried leaving out gdk_threads_enter()/leave() in the CPU-intensive function, but X gives me errors. tom ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
Tomas Carnecky wrote: Michael McCann wrote: Michael R. Head wrote: On Tue, 2007-12-18 at 17:14 -0500, Michael R. Head wrote: I assume you meant g_threads_init(); gdk_threads_init(); gtk_init(); gdk_threads_enter(); gtk_main(); gdk_threads_leave(); right? Yes, that is correct. :) Does your special function take time to do its job? If so, then that would be why. For example: ... while(1) { gdk_threads_enter(); sleep(1) gdk_threads_leave(); sleep(10) }; ... you'd freeze your app for a second every 10 seconds. Ahh, ok. How else can I accomplish my goal, then? I need to give GTK the Which goal? Describe what your app is supposed to do. tom I want to fix the issue of the UI freezing when the CPU-intensive function, which is on a separate thread and calls GDK, is executed. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
On Tue, 2007-12-18 at 18:46 -0500, Michael McCann wrote: Ahh, ok. How else can I accomplish my goal, then? I need to give GTK the lock, as I'm calling GDK from another function not in the main GTK loop. I tried leaving out gdk_threads_enter()/leave() in the CPU-intensive function, but X gives me errors. Well, I guess what you need to do is to separate out the CPU intensive bits of the function from the widget manipulation bits... my_function() { compute_real_hard(); gdk_threads_enter(); update_ui(); gdk_threads_leave(); } Or something like that. mike -- Michael R. Head [EMAIL PROTECTED] suppressingfire.org ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
I'll break protocol and reply to my own message _again_... On Tue, 2007-12-18 at 19:05 -0500, Michael R. Head wrote: On Tue, 2007-12-18 at 18:46 -0500, Michael McCann wrote: Ahh, ok. How else can I accomplish my goal, then? I need to give GTK the lock, as I'm calling GDK from another function not in the main GTK loop. I tried leaving out gdk_threads_enter()/leave() in the CPU-intensive function, but X gives me errors. Well, I guess what you need to do is to separate out the CPU intensive bits of the function from the widget manipulation bits... my_function() { compute_real_hard(); gdk_threads_enter(); update_ui(); gdk_threads_leave(); } Or something like that. Also, you can skip using gdk_threads_enter() and gdk_threads_leave() if you instead use g_idle_add(update_ui) and make update_ui a suitable callback: http://library.gnome.org/devel/glib/stable/glib-The-Main-Event-Loop.html#g-idle-add mike mike -- Michael R. Head [EMAIL PROTECTED] suppressingfire.org ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
Michael McCann wrote: Michael R. Head wrote: Does your special function take time to do its job? If so, then that would be why. For example: ... while(1) { gdk_threads_enter(); sleep(1) gdk_threads_leave(); sleep(10) }; ... you'd freeze your app for a second every 10 seconds. Ahh, ok. How else can I accomplish my goal, then? I need to give GTK the lock, as I'm calling GDK from another function not in the main GTK loop. I tried leaving out gdk_threads_enter()/leave() in the CPU-intensive function, but X gives me errors. Don't use gdk in the CPU-intensive function: while(1) { sleep(1); do_time_consuming_task(); gdk_threads_enter(); update_ui(); gdk_threads_leave(); } You may need to factor out some code, but this is the right (read: only) way to do it if you don't want to block the UI. -brian ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
On Tue, Dec 18, 2007 at 07:05:18PM -0500, Michael McCann wrote: Tomas Carnecky wrote: Michael McCann wrote: Michael R. Head wrote: On Tue, 2007-12-18 at 17:14 -0500, Michael R. Head wrote: I assume you meant g_threads_init(); gdk_threads_init(); gtk_init(); gdk_threads_enter(); gtk_main(); gdk_threads_leave(); right? Yes, that is correct. :) Does your special function take time to do its job? If so, then that would be why. For example: ... while(1) { gdk_threads_enter(); sleep(1) gdk_threads_leave(); sleep(10) }; ... you'd freeze your app for a second every 10 seconds. Ahh, ok. How else can I accomplish my goal, then? I need to give GTK the Which goal? Describe what your app is supposed to do. tom I want to fix the issue of the UI freezing when the CPU-intensive function, which is on a separate thread and calls GDK, is executed. Then put your CPU-intensive code on another proces an give data back on a file descriptor when you are redy. This is the common way to do it! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- Göran Hasse Göran Hasseemail: [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: Multi-threaded UI Freezes on GDK Call
Brian J. Tarricone wrote: Michael McCann wrote: Michael R. Head wrote: Does your special function take time to do its job? If so, then that would be why. For example: ... while(1) { gdk_threads_enter(); sleep(1) gdk_threads_leave(); sleep(10) }; ... you'd freeze your app for a second every 10 seconds. Ahh, ok. How else can I accomplish my goal, then? I need to give GTK the lock, as I'm calling GDK from another function not in the main GTK loop. I tried leaving out gdk_threads_enter()/leave() in the CPU-intensive function, but X gives me errors. Don't use gdk in the CPU-intensive function: Unfortunately, the GDK calls _are_ what is CPU-intensive. I believe the gdk_pixbuf_get_from_drawable() call is the most intensive. None of my regular code is CPU-intensive. Of course, if I clocked my CPU back up to 3.2GHz, this wouldn't be a problem. ;D However, I can't count on my users having a fast CPU. I'll try out that g_idle_add() method tomorrow... ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
Michael R. Head wrote: I'll break protocol and reply to my own message _again_... On Tue, 2007-12-18 at 19:05 -0500, Michael R. Head wrote: On Tue, 2007-12-18 at 18:46 -0500, Michael McCann wrote: Ahh, ok. How else can I accomplish my goal, then? I need to give GTK the lock, as I'm calling GDK from another function not in the main GTK loop. I tried leaving out gdk_threads_enter()/leave() in the CPU-intensive function, but X gives me errors. Well, I guess what you need to do is to separate out the CPU intensive bits of the function from the widget manipulation bits... my_function() { compute_real_hard(); gdk_threads_enter(); update_ui(); gdk_threads_leave(); } Or something like that. Also, you can skip using gdk_threads_enter() and gdk_threads_leave() if you instead use g_idle_add(update_ui) and make update_ui a suitable callback: http://library.gnome.org/devel/glib/stable/glib-The-Main-Event-Loop.html#g-idle-add mike Ok, I tried the g_idle_add() idea out: NonUIThread Calls foo() - foo() calls g_idle_add(), which is passed a GSourceFunc, bar(), along with some data it needs - bar() runs a bunch of GDK calls (gdk_threads_enter()/leave() is _not_ called, neither in foo() nor bar()) foo(), after calling g_idle_add(), immediately begins executing statements after the g_idle_add() call. However, bar() still holds up the UI... Ack! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
Michael McCann wrote: Brian J. Tarricone wrote: Don't use gdk in the CPU-intensive function: Unfortunately, the GDK calls _are_ what is CPU-intensive. I believe the gdk_pixbuf_get_from_drawable() call is the most intensive. None of my regular code is CPU-intensive. How large is the GdkDrawable? I wouldn't imagine that to eat too much CPU. You can try only acquiring the gdk lock in your thread when absolutely necessary to see if that helps, like this: do_something_without_gdk(); gdk_threads_enter(); gdk_pixbuf_get_from_drawable(); gdk_threads_leave(); do_other_stuff_without_gdk(); gdk_threads_enter(); do_some_stuff_with_the_gdk_drawable(); gdk_threads_leave(); ... Obviously you don't want to go nuts taking and dropping the lock over and over, but this might help track down (or even eliminate) what part of your code is blocking and causing the UI to freeze (add some printf()s in there too, I guess). -brian ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
Brian J. Tarricone wrote: Michael McCann wrote: Brian J. Tarricone wrote: Don't use gdk in the CPU-intensive function: Unfortunately, the GDK calls _are_ what is CPU-intensive. I believe the gdk_pixbuf_get_from_drawable() call is the most intensive. None of my regular code is CPU-intensive. How large is the GdkDrawable? It's the size of the entire screen: 1024x768 I wouldn't imagine that to eat too much CPU. You can try only acquiring the gdk lock in your thread when absolutely necessary to see if that helps, like this: do_something_without_gdk(); gdk_threads_enter(); gdk_pixbuf_get_from_drawable(); gdk_threads_leave(); do_other_stuff_without_gdk(); gdk_threads_enter(); do_some_stuff_with_the_gdk_drawable(); gdk_threads_leave(); ... Yes, I've already tried that, to no avail. My code basically only consists of: gdk_screen_get_default(): Get the default screen gdk_screen_get_root_window(): Get the root window gdk_pixbuf_get_from_drawable(): Get a pixbuf from the entire screen gdk_pixbuf_save_to_bufferv(): Save the pixbuf to a buffer. Remove all of the GDK calls, and there is no UI freeze. I can even throw in an infinite loop to any function in the non-UI thread, and the UI does not freeze, which is to be expected. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Multi-threaded UI Freezes on GDK Call
I've got a multithreaded GTK application. One thread runs gtk_main(): gtk_threads_enter(); gtk_main(); gtk_threads_leave(); The other thread is an infinite loop that sleeps for one second on each loop. Every x seconds, the infinite loop calls a function, which makes some GDK calls. At the beginning of this function, gdk_threads_enter() is called; at the end, gdk_flush() and gdk_threads_leave() is called. Whenever this function is called, the UI freezes and CPU usage jumps to 100% for about one second (no other applications freeze, of course). I've tried calling gdk_threads_leave()/enter() before and after each GDK call to no avail. I run g_thread_init() and gdk_threads_init() at the beginning of my program. In the function, gdk_screen_get_default(), gdk_screen_get_root_window(), gdk_pixbuf_get_from_drawable(), and gdk_pixbuf_save_to_bufferv() are called. I'm using NetBSD on a P4 1.2GHz. What am I doing wrong? I've asked this question on IRC (irc.gnome.org, #gtk+) but noone seems to know the problem. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Multi-threaded UI Freezes on GDK Call
On Tue, 2007-12-18 at 20:37 -0500, Michael McCann wrote: Brian J. Tarricone wrote: Yes, I've already tried that, to no avail. My code basically only consists of: gdk_screen_get_default(): Get the default screen gdk_screen_get_root_window(): Get the root window gdk_pixbuf_get_from_drawable(): Get a pixbuf from the entire screen OK, yeah, this operation will probably be slow! Taking a screenshot is a time consuming op. I don't think there's much to do about that. I mean, just run the Applications/Accessories/Take Screenshot app to see how long it takes. There is probably a better way to implement your app. What exactly do you want to do? gdk_pixbuf_save_to_bufferv(): Save the pixbuf to a buffer. Remove all of the GDK calls, and there is no UI freeze. I can even throw in an infinite loop to any function in the non-UI thread, and the UI does not freeze, which is to be expected. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- Michael R. Head [EMAIL PROTECTED] http://picasaweb.google.com/demiri.head.wedding ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list