Re: GChildWatch source -- take two



On Thu, 2003-07-24 at 12:10, Jonathan Blandford wrote:
> "Alexis S. L. Carvalho" <alexis cecm usp br> writes:
> 
> > Same problem: the thread that calls waitpid is the one that runs in the
> > function main, and because of bugs in LinuxThreads it can't wait for the
> > children of the other threads.
> 
> Looking again, that analysis doesn't make sense.  We run the following
> code in a thread:
> 
>   ...
>   new_main_loop = g_main_loop_new (NULL, FALSE);
>   pid = get_a_child ();
>   source = g_child_watch_source_new (pid);
>   g_source_set_callback (source, (GSourceFunc) child_watch_callback,  NULL, NULL);
>   g_source_attach (source, g_main_loop_get_context (new_main_loop));
>   g_source_unref (source);
>   g_main_loop_run (new_main_loop);
>   ...
> 
> That means that the thread should be alive when the child exits, and the
> waitpid should be run from within that thread by the new_main_loop
> within that thread.

Remember, it's the GMainContext which is the heavyweight structure,
GMainLoop is essentially just 

 struct _GMainLoop {
   GMainContext *context;
   gboolean running;
 };

If the GMainContext is already being used in another thread, then
calling g_main_loop_run() is basically simply an efficient way
of doing

 while (loop->running)
  /* nothing */;

The callbacks get executed in the other thread. Could that be what's
going on here?

Regards,
						Owen







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