From: youngn@logica.co.uk (Nicholas Young)
Subject: Results (longish): Waiting on X event & VMS event flag
Date: Fri, 29 Jul 1994 18:35:55 GMT [thread overview]
Message-ID: <youngn-2907941835550001@158.234.17.99> (raw)
I wrote:
> Can anyone help, please ...
Lots of people sent replies, some including sample code - many thanks.
Results are below; if I have misunderstood anyone, sorry! I have not
included suggestions that turned out not to work - but thanks for replying
anyway. I hope this lot is useful, if only in a negative way, to someone
...
> I have an Xt-based program running on OpenVMS/Alpha that needs to wait
> simultaneously on X events and VMS event flags. [Don't ask why :-)] Is
> there an easy way to do this? Possibilities seem to be:
I should have made it clearer that I was looking for the most portable
solution, since I am also considering a port to Unix [sorry for mentioning
the U-word in the VMS groups :-)]. However, all solutions were and are
welcomed.
> 1) Use XtAppAddInput (best, because portable). Can the alternative input
> source be made to wait on event flags?
I would have saved myself and a lot of other people some time if I had
realised and stated that it's a *common* event flag that I need to wait
on. XtAppAddInput does indeed use an event flag for its alternative input
source, but only a local one in cluster 0. So this alone is no good.
However, the way I shall probably go is to persuade the communicating app
to change to use a different IPC mechanism, e.g. a mailbox or a lock.
Then I can set up an AST to be delivered when there is IPC and use that to
set a *local* event flag which I can wait on in the main Xt loop. This
seems like the most portable mechanism and doesn't involve too much
rewriting of my other process.
IMHO the VMS implementation of XtAppAddInput is rather poorly designed,
only allowing local event flags; you would think that external comms would
be an likely requirement. The event flag design seems to be the
fundamental problem - you can't wait for event flags in more than one
cluster. Someone did think he remembered that issue being resolved, but
no-one has yet said how it was done. If anyone knows, please tell me.
> 2) Go below the X level and use something else. Is XNextEvent implemented
> using QIOs, and if so can I both use them to get X events and also to wait
> on event flags? Or does X use some obscure VMS mechanism?
The answer seems to be: X does use QIOs, as you would expect. There is a
Motif device driver manual, which some people pointed me to. However, it
doesn't include function codes for reading events - it seems in fact quite
useless for most purposes. The only things you can really do as far as I
can see are things like setting the pointer position. The function codes
aren't defined in the system headers either. I checked with DEC, and
their reaction was: we could do it for you, but it doesn't come under your
support contract, so we'll have to charge you for it. I have not pursued
that one yet.
> 3) [Last resort] Write a separate app/thread that sits there waiting for
> the event flag and dispatches some sort of alternative input to the Xt
> loop (see (1)).
Nobody else liked this one either :-)
> Or is there a better way that I've missed?
Other suggestions were:
- Use XSelectAsyncInput (a VMS-specific call). This allows all X events
to be delivered as ASTs, so that the CEF wait is the main loop. Apart
from not fitting in well with the main Xt loop, this is impracticable for
Motif because it is a per-window call which has to be called at the right
time for the right set of events. In Motif, window processing tends to be
inside widget procedures that you can't access; also, there are rather a
lot of windows! It's worth pursuing if you're just using X, though.
- Use XMultiplexInput. This is apparently another VMS-specific call; but
DEC hadn't heard of it, and it's not in the manuals, so I gave that one up
... I suspect it would only use local event flags anyway.
- Use ASTs which check for common event flags and then reset themselves.
The disadvantage of this is that you keep having to poll, even if it's
only at intervals (and probably doesn't use any CPU to speak of). One
could in fact use an Xt timer (more portable) to achieve the same thing,
or any timed polling mechanism below the level of the event loop.
However, my app needs to respond as fast as possible to the CEF, so timers
are not ideal, and if you have them going off too often they do start to
affect performance.
[The person who contributed this (Dom Maddalone, thanks Dom) also
suggested distributed locks with blocking ASTs; if I understand this
correctly it would also mean a timed mechanism - but please correct me if
I am wrong.]
- Don't use common event flags(!) This is in fact what I shall do; see
above. It originally seemed that CEFs were an absolute constraint, but it
turns out not to be quite so bad. But this has been a fascinating
exercise. :-)
Comments welcome,
Thanks again,
Nicholas.
--
Nicholas Young. Opinions expressed above are mine, not Logica's.
I am often away; please mail me if you wish to be sure I see articles.
"'Macbeth' is a play written by a man who, on this occasion at least, if he had the talent, ought to have written a fairy tale." - J.R.R.Tolkien.
reply other threads:[~1994-07-29 18:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox