Threads and GTK+



I've read the FAQ, and basically everybody I have talked to has told me to
never use GTK+ in a thread, so I don't, but I was trying to skirt across
the issue when I ran into a problem that I was hoping somebody might have
some info on.

I have a GTK+ app that would like to fork in one spot and either execute a
program that does non-GTK+ X related stuff, or just call the code after a
fork inside the GTK+ program AFTER closing all GTK+ related resources that
the child inherited from the parent process.  Neither works.  I get
messages that say  Xlib:  unexpected async sequence and then some badass
BadFont errors from X when certain ExposeEvents get sent to the parent
GTK+ app.

How to get around this?  I know you're not supposed to use threads in
GTK+, and I'm trying to bend over backwards to avoid it.  Is it not
possible to fork and execute any X related code in the child at all
without screwing up the parent?

A related question is whether or not child fork()ed processes inherit heap
memory as pointers, or as heap memory.  If I do say,

myptr = g_new(char, 1024);

if(fork()==0)
{
   /* Is myptr in here heap memory that should be g_free()d or is a 
    * regular pointer  (connected to parent memory?)
   */
}

exit;

If anybody knows how to "cheat" gtk+ and get non-gtk+ threading to work,
I'd appreciate hearing about it.  The process I want to execute in the
child process will basically wait and wait and wait indefinately, so I
can't do it without forking otherwise my program won't return to gtk_main
after the callback and continue to do vital things like redrawing, etc.

David Allen

http://opop.nols.com/ Free Software Development
Der Horizont vieler Menschen ist ein Kreis mit Radius Null -- und das
nennen sie ihren Standpunkt.



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