strange D-Bus interactions with gtk_dialog_run
Gnaural
gnaural at users.sourceforge.net
Mon Nov 26 09:42:15 PST 2007
Well, turns out this probably isn't a D-Bus problem at
all; a bit more investigation suggests that the bad
interaction is really ANY separate thread with
specifically "gtk_file_chooser_dialog_new" (NOT
gtk_dialog_run).
Maybe I'm just doing something stupid; whichever, I'll
post that question to the gtk-devel list. I'm just
posting this here to put to rest the idea I proposed
that the problem was with D-Bus.
BTW, here's my proof that any old thread will bomb out
(at in Gnome 2.20.1 on Debian 2.6.22-6, gcc version
4.1.3 20071019 (prerelease) (Debian 4.1.2-17))):
/* Demonstration of bad
gtk_file_chooser_dialog_new/thread interaction
* compile with:
* gcc `pkg-config --libs gtk+-2.0 gthread-2.0` main.o
-o HelloThreadBreaker
*/
#include <unistd.h>
#include <gtk/gtk.h>
void *sleep_for_awhile (void *args)
{
time_t t1;
time_t t2;
g_print ("Going to sleep for 100 seconds\n");
time (&t1);
sleep (100);
time (&t2);
g_print ("I slept for %d seconds\n", (int) (t2 - t1));
return NULL;
}
int main (int argc, char *argv[])
{
char *filename;
GError *error = NULL;
GtkWidget *dialog = NULL;
g_thread_init (NULL);
gdk_threads_init ();
gdk_threads_enter ();
gtk_init (&argc, &argv);
if (!g_thread_create (sleep_for_awhile, NULL, FALSE,
&error))
{
g_printerr ("Failed to create sleep_for_awhile thread:
%s\n",
error->message);
return 1;
}
dialog = gtk_file_chooser_dialog_new ("Open File",
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN,
GTK_RESPONSE_ACCEPT, NULL);
if (gtk_dialog_run (GTK_DIALOG (dialog)) ==
GTK_RESPONSE_ACCEPT)
{
filename = gtk_file_chooser_get_filename
(GTK_FILE_CHOOSER (dialog));
g_free (filename);
}
gtk_widget_destroy (dialog);
gtk_main ();
gdk_threads_leave ();
return 0;
}
More information about the dbus
mailing list