rcbc@forseti.cs.cornell.edu (Robert Cooper) (03/27/90)
We've run into a rather tricky problem with the way X11 handles input events and the way Isis handles input on multiple file descriptors. This problem occurs with the "grid" demo, on X11 releases 3 and 4 (and possibly earlier releases). grid will often fail to repaint itself when its window is uncovered. Actually the problem is not confined to Isis, but will happen in any program that uses needs to listen to input from multiple sources, including X. Basically the XFlush routine secretly reads data off the X file descriptor and puts it in the X input event queue. This is a real problem when your program does something like the following sequence: do some X output XFlush(display); do a select on the X file descriptor and some of your own file descs. if the X file descriptor has input pending then process X input The select doesn't see the new X input events because they've already been read. The "obvious" solution of processing all pending events after doing a flush is a problem because almost any input event that needs processing involves output and many output routines silently call XFlush as they need to. In fact the XFlush in the above sequence is usually unnecessary to trigger this behaviour. Does anyone know a good solution to this problem? I've fixed "grid" with a kluge that involves checking for events, and processing them after (almost) every output. This is quite messy. Perhaps Isis should have a notion of user callable "work_pending" routines in addition to file descriptors? I'd rather not do this just to fix a bad citizen like X. (The question remains of why XFlush does input at all. It does this in response to EWOULDBLOCK errors on output. Presumably on some systems that X runs on output blocks when there is pending input on the same descriptor.) -- Robert Cooper (rcbc@cs.cornell.edu)