Re: nested gdk_threads_enter() hangs: linux/gcc vs. win32/mingw?



Hi,

Am Samstag, den 14.05.2005, 12:26 +0200 schrieb Felix Kater:
Hi,

I am using the same code on win32/mingw and linux/gcc, however, when I execute the code on linux, the 
programm hangs at the second (nested) call of gdk_threads_enter(), see below.

Am I doing something illegal to use nested calls of gdk_threads_enter()?
If not, is there a flag to allow/disallow nested calls I miss on linux?

Funny. On FreeBSD I have no problems with nested calls of
gdk_threads_enter()/gdk_threads_leave().

As I understand the description of these functions and their usage you
could compare it with a mutex-semaphore.
The first call of gdk_threads_enter() checks whether the mutex is locked
and waits for unlocking. When the mutex is unlocked it will be locked by
the next call.
gdk_threads_leave() unlocks the mutex, so the next call of
gdk_threads_enter() can lock it again. And so.

You can compare it with a parking lot. If it is free you can drive in.
If not you have to wait until it is free.

This mutex-semaphore is gdk-wide.

As you can see, you MUST not call them nested!

But it is better to put gdk_threads_enter()/gdk_threads_leave() only
around the gtk/gdk-function.

You better write the following:


f_create_label( /* ... */ ){

  other_non_gtk_code

  gdk_threads_enter();   /* <--- 2. time: hangs on linux/gcc */

  gtk/gdk-function

  gdk_threads_leave();
  
  other_non_gtk_code

}


f_add_label_to_parent()( /* ... */ ){

  other_non_gtk_code

  gdk_threads_enter();   /* <---1. time entered */

  gtk/gdk-function

  gdk_threads_leave();

  other_non_gtk_code

  f_create_label( /* ... */ );

  gdk_threads_enter()

  gtk/gdk-function

  gdk_threads_leave();

  other_non_gtk_code
}


main(){

  gdk_threads_init();
  gtk_init();  

  /* ... */

  f_add_label_to_parent( /*... */ );

  /* (programm never reaches here) */

  gdk_threads_enter();
  gtk_main();
  gdk_threads_leave();

}

Hope this helps.

Best regards

JÃrgen


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