[comp.windows.x] Avoiding Event Loops

cookson@helios.mitre.org (Cookson) (05/29/90)

I'm writing a simulation that has a main loop that must be executed
with preference over the event loop. (Can't hang around and wait for events),
But I also want a robust handling of user generated events.  How can I
(on a unix machine) run the simulation loop and the event loop in parallel?

Thanks in Advance,
Dean


% Dean Cookson				  $ Anyone can be taught to sculpt    %
% dcookson@mitre.org			    $ Michaelangleo would have had to %
% {devax,et al..}!linus!mbunix!helios!cookson $ have been taught how not to.  %
% Disclaimer: My opinions are my own, and       $ The same is true of great   %
%       are of questionable sanity                $ programmers               %

klee@wsl.dec.com (Ken Lee) (05/29/90)

In article <109658@linus.UUCP>, cookson@helios.mitre.org (Cookson) writes:
|> I'm writing a simulation that has a main loop that must be executed
|> with preference over the event loop. (Can't hang around and wait for
events),
|> But I also want a robust handling of user generated events.  How can I
|> (on a unix machine) run the simulation loop and the event loop in parallel?

There are several ways to do this, depending on the form of input from
your simulation.  On most UNIX systems, Xlib uses select() to wait for
events from the server.  If your simulation is a separate process, you
can select() on both the X server and the simulation process.  In
effect, this uses the UNIX scheduler to timeshare your user interface
process and simulation process.  Another alternative is to use one of
the multi-threads packages to do this timesharing within one process.
You might also do this multi-threading more efficiently yourself, by
taking advantage of implementation details.  Finally, look into the
work, input, and timer proc stuff in the X Toolkit for a few more
ideas.

Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee