gmain context/loop issue



Hello!
I am having a problem with the glib main context or g_main_loop. This is
running on Ubuntu Linux 8.0.4 and Fedora 10. I have an app that needs to
spawn and control another app. I am calling g_spawn_async_with_pipes
from a secondary thread in a shared library, not the main app. I
manually create and attach GSource objects and callbacks for the stdin,
stdout and stderr pipes. I then create my own CMainContext object and
enter a loop calling g_main_context_iteration with my context and FALSE
for the blocking parameter. (I don't call the dispatch function because
g_main_context_iteration() calls that.) I then check to see if an event
has been signaled using a 10 msec timeout. If the event has not been
signaled then I continue looping. The event will be signaled based on
messages from the stdout pipe. This works fine.

The problem is that *IT SEEMS* like the main loop in my exe has stopped
and I can't get it started again. When the called app terminates, I
signal that subsequent processing should resume. This involves sending a
message to the original app main loop, but nothing happens. When I break
into GDB the app is waiting at a poll function (poll() called from
g_main_loop_run()) even though I sent a message that should have
triggered more processing. I set a breakpoint in the shared library code
that should be invoked in response to that message but it is never hit.


I have tried sending that 'continue' message both from the thread with
the secondary main context 'loop' and from the original app main thread
(both in the shared library), but both fail the same way. I have also
tried calling g_main_context_wakeup(NULL) back in the main app thread
(in the shared library), but that didn't help either.

I would expect that a single multi-threaded app could run multiple
'main' loops simultaneously as long as they don't overlap resources. Is
that true? I am thinking of these main loops like a Windows message
pump. Is that reasonable?

I would really appreciate it if someone could help me understand why I
can't get the original app main loop to receive and process my messages.
I have read the GLIB info and suspect that there may be a problem with
the fact that I am running in a shared library though this isn't a
recursion issue.

Thank you,
Chuck Crisler





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