home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!sol.ctr.columbia.edu!destroyer!ubc-cs!uw-beaver!micro-heart-of-gold.mit.edu!bu.edu!dartvax!fluent!creare!inb
- From: inb@creare.COM (Ian Brown)
- Newsgroups: comp.windows.x
- Subject: Re: fork()ing in an event loop??
- Message-ID: <13398@creare.COM>
- Date: 22 Jul 92 18:07:55 GMT
- References: <1992Jul8.181508.29548@tc.cornell.edu> <1992Jul14.202317.10570@thunder.mcrcim.mcgill.edu>
- Reply-To: inb@creare.UUCP (Ian Brown)
- Organization: Creare Inc., Hanover, NH
- Lines: 36
-
- In article <1992Jul14.202317.10570@thunder.mcrcim.mcgill.edu> mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes:
- :>> I have a grapher that gets input from stdin. Once it has been told
- :>> to plot, it opens an window, and plots. Then of course I go into an
- :>> event loop that processes expose events. The problem is, I want to
- :>> process these events at the same time (and in the background) as I
- :>> get more lines of input from stdin. I think what I need to do is
- :>> fork(), but I don't really know how to do it.
- :>
- :>If you're using Xt, then you just use XtAppAddInput to add file
- :>descriptor 0 as a source of input, then have its callback read and
- :>process the lines.
-
- Note that this doesn't always work very well. On some systems, your event
- handler will be called constantly, regardless of whether or not any new data is
- ready to be read on stdin. If the code needs to be portable, an alternative
- would be to use a timer (XtAppAddTimeout) and perform non-blocking I/O to
- actually read the file (you could do the non-blocking I/O in the handler for
- XtAppAddInput, but you will effectively have a busy loop.)
-
- I found out what a problem this can be when trying to port a routine that used
- XtAppAddInput from an HP-UX machine (where it worked correctly) to a Sun
- machine (where it didn't). Since my code was expecting to find something to
- read, it would lock up in the event handler when nothing was available.
-
- In my case, I was using pipes for the I/O. If you aren't using pipes, this may
- or may not apply (I don't remember offhand whether this is documented in the X
- toolkit books or under select() and don't feel like searching unless someone
- really wants me to.)
-
-
-
-
-
- --
- Ian Brown
- inb@creare.com
-