[gtkada] GtkAda and tasking
Robin, Stephe, or Nora
leakstan at erols.com
Fri Apr 21 16:16:34 CEST 2000
Earlier, I wrote:
> So now the question is, can the Gtk event queue be made to call
> Common_Event.Notify? If there is a hook that is called for every
> event, that would work.
After thinking about this a while, it's clear that the answer is "no".
The real event queue is maintained by the operating system (X Windows
or Win32), and does not provide such a hook.
Another solution (as JP Rosen suggested) is to somehow cause the main
loop to break out so its thread can do a rendezvous, then continue.
This could be done by defining a new event. In Win32, the main loop
looks roughly like:
Main:
loop
Status := Win32_GetMessage (Message'access, ...);
case Status is
when -1 =>
-- some error
when 0 =>
-- WM_QUIT received
exit Main;
when others =>
-- dispatch message
end case;
end loop Main;
It would be straitforward to define a new message, say WM_PAUSE:
Main:
loop
Status := Win32_GetMessage (Message'access, ...);
case Status is
when -1 =>
-- some error
when 0 =>
-- WM_QUIT received
exit Main;
when others =>
case Message.Message_ID is
when WM_PAUSE =>
accept User_Entry do
...
end User_Entry;
when others =>
-- dispatch message
end case;
end case;
end loop Main;
Then the user task that wants to communicate with the GUI task would
first post a WM_PAUSE, using Win32_Post_Message, then wait for the
User_Entry rendezvous.
I'm not clear how to do the analogous things in Gtk. I guess WM_PAUSE
would have to be a new event type; either add to
gdktypes.h:GdkEventType, or do something similar at the Gtk level.
More difficult is Win32_Post_Message; this is a thread-safe way for
one thread to add an item to a queue owned by another thread. I don't
think Gtk has such an operation! The closest I can find is
gdkevents.c:gdk_event_put, which is _not_ task safe.
As a suggestion, if you can use a Win32 only approach for now, get
Windex (http://www.erols.com/leakstan/Stephe/Ada/windex.html), modify
the main loop as above (override Windex.Message_Loops.Run), and see if
it really works for you. Then we can propose that as a model for how
Gtk needs to work.
-- Stephe
More information about the gtkada
mailing list