Re: Can someone help me get rid of XLib errors? please



>   When i run my gtk app, sometimes to program crashes because of an Xlib 
>   error. Now i know this has to do with thread synchronization, and I
>   heard that only 1 thread can access gtk functions at a time. So i went 
>   online, and I found an example which used pthreads. and that noted 
>   just to use gdk_thread_init, at the and gdk_thread_enter and 
>   gdk_thread_leave before and after gtk_main, respectively. While this 
>   method compiled, I get an immediate Segmentation fault as soon as I 
>   run  my program. Currently, I only use gdb as a debugger, and that
>   hasn't helped. any ideas to beat this Xlib problem? thanks!

Umm...Have you had a look at the api docs on the gtk_thread_XXX functions?

I'm not totally familiar with the gtk functions, but it looks pretty
straight forward (threads are pretty easy). Basically gtk keeps a set
of mutex locks, and you have to manually manage them.

To start with you need to lock gtk_main() with a gtk_thread_enter() /
gtk_thread_leave() around it. However, you also need to perform a 
similar lock around each access to gtk functions in your callbacks...

Segmentation fault sounds like you're not initialising properly.
Are you sure you've :

g_thread_init (NULL);
gdk_threads_init ();
gtk_init (&argc, &argv);

If you have, check your callbacks: Are you sure you're locking around
any calls to gtk functions? (ie. gtk_thread_enter() and gtk_thread_leave()
around ANY call to gtk in call backs)...

The documentation is pretty um...basic. You might want to think about
using gtk_main_interation_do() with the lock/unlock around it if you
want to do fancy things like move where you're event processing is
taking place around.

Anyway, hope that helps. If not you'll have to be more specific in your
question.

ciao,
Doug.




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