Re: gdk_threads_enter() hangs
- From: "Frank W. Miller" <fwmiller cornfed com>
- To: Todd Fisher <taf2 lehigh edu>, gtk-app-devel-list gnome org
- Cc:
- Subject: Re: gdk_threads_enter() hangs
- Date: Sat, 29 May 2004 18:13:42 -0400
Thanks for the reply.
I am initializing the thread system just as you outlined. My code is
basically identical. I will try taking out the other calls that are
made by callbacks. I was unaware of the need to handle the callbacks
this way...
FM
Todd Fisher wrote:
Hi Frank,
this is most likely because you are either:
a. not initializing the threading system correctly.
b. calling gdk_threads_enter within the main thread.
for example in main you should make sure you're initalizing gtk+
similar to the following:
int main( int argc, char **argv )
{
/* thread init */
g_thread_init( NULL );
gdk_threads_init();
gtk_init( &argc, &argv );
...
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
return 0;
}
to satisfy condition b make sure you are not calling
gdk_threads_enter/leave within any callbacks
main(){
...
g_signal_connect( obj, "clicked", func, NULL );
...
}
void tfunc( gpointer null )
{
gdk_threads_enter();
/* update some graphical indicator */
gdk_threads_leave();
}
void func( GtkWidget *widget, gpointer null )
{
GThread *tid;
/* gdk_threads_enter(); ERROR this would cause a dead lock such as
the one you describe because
main thread already holds the lock */
tid = g_thread_create( tfunc, NULL, FALSE, NULL );
}
for a more complete example:
severna.homeip.net/source/examples/simple.tar.gz
hope this helps,
-todd
Frank W. Miller wrote:
Greetings,
I'm having some strange behaviour. I am writing a threaded Gnome app
and it seems to be hanging when I call gdk_threads_enter(). Here's
the code snippet where it hangs up:
printf("gdk_threads_enter()\n");
gdk_threads_enter();
printf("gdk_threads_enter() returned\n");
The output is (as you might guess):
gdk_threads_enter()
The second printf is never executed. I've been over all my various
gdk_threads_enter()/gdk_threads_leave() pairs to make sure I'm not
locking GDK and then not unlocking it. It seems to me to be fine.
All the protected areas are very short, i.e. 1 or 2 lines of code,
and the protected code is all just calls to gtk stuff. I'm not doing
any I/O inside of a protected area. Any thoughts on this?
Thanks in advance,
FM
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]