Re: gthread and fork/exec



Hi,

> I am trying to use gthread and fork/exec to have a thread and child
> process.  It seems both thread and child process cannot work properly,
> namely, there is no new /tmp/testfile generated, and the thread may
> not work sometime. It is the same when using g_spawn_ ...

This has nothing to do with ORBit. Its a GLib question. Next time ask at
gtk-list@gnome.org.

To your program: It runs here without problems. But there are some
problems, which make running fork in GLib multithreaded programs
unreliable. Just now there is no g_thread_atfork command like in
pthread. It would be needed to really make it work. See the
pthread_atfork manpage, why this is needed.

I don't think, we ever want to have anything like that in GLib however.
Think of all the possible yummy deadlocks with pthread_atfork. That is
not good. There is a very easy guideline: Do not mix threads/fork unless
you don't use any glib funtions in the forked child. Period. g_spawn
however looks save to use (instead of fork). We might want to add that
info regarding threads/forks somewhere in the GLib documentation.

So can you be a little more elaborate, why your program is failing.
BTW easier to check than ("touch", "touch", "/tmp/testfile", NULL) would
be ("echo", "echo", "hello world", NULL).

Remove the g_message calls from the child. They might block forever, if
fork was called, when the correspondiong mutex was just locked.

Bye,
Sebastian
-- 
Sebastian Wilhelmi
mailto:wilhelmi@ira.uka.de
http://goethe.ira.uka.de/~wilhelmi





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