[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

595.0. "A long compute bound Activate Procedure" by PHOBOS::WICKERT (Dave. DTN:321-5206) Thu Apr 13 1989 15:01

    I have a routine that takes about a minute to run (mostly compute
    bound but doing some file I/O also) and I would like to occasionally
    write out status messages to a simple text widget in a "messages"
    portion of my main window... something to tell the user that I am
    still alive..
    
    Since I will be in an ACTIVATE procedure for a long time -- I need
    to flush the XLIB and toolkit event queue from within my activate
    procedure... what is the intrinsic that I should use?  I would call
    it about every 5-10 seconds or so..
    
    Thanks.
    
    _-_- Dave
    

T.RTitleUserPersonal
Name
DateLines
595.1Something like this?PHOBOS::WICKERTDave. DTN:321-5206Fri Apr 14 1989 00:4817
    I think that I want something like:
    
    static void ProcessXInputQueue()
    {
    	XEvent *event
    
    	while(XtPending) {
    	   XtNextEvent(event);
           XtDispatchEvent(event);
    	}
    }
    
    And call it as often as I can... Right?
    
    _-_- Dave
    

595.2Gotcha?DECWIN::KLEINFri Apr 14 1989 12:3129
>>    And call it as often as I can... Right?

But beware of REENTRANCY.  What will you do if the user does the
necessary menu pulldowns, etc, to call your long-running proc
reentrantly from inside the XtDispatch which is inside the long-running proc?
The toolkit will not prevent or detect reentrancy of this type.
But things can get very messy nevertheless...

You might consider handling only certain types of events in your inner loop,
deferring or discarding other event types (like buttonpress, release, etc).
Then, you have to be careful that you don't do things like throw away a
downclick but not the upclick, and that the relative order of
events stays "sane".  That is, you'll have to maintain the relative
order of MapNotifies and Expose, etc, so that widgets don't get
confused.

Detecting reentrant calls to your proc may be the best idea.  But
you have to watch out for secondary effects.  For example, suppose
that while your long-running proc is running, the user selects
something from the menu that depends on the results of the long-running
operation.  The second operation needs to either wait for the
first one to complete, or you need to report to the user that
he can't do both things at once.  Selecting the original action
reentrantly is just a special case of this general dependency problem.

So, it isn't *that* simple.

-steve-

595.3LEOVAX::TREGGIARIFri Apr 14 1989 13:5540
You can prevent the reentrancy problem by displaying a modal work in progress
box.  The toolkit will then throw away any mouse and button events which
are not sent to the work in progress box itself.

>    static void ProcessXInputQueue()
>    {
>    	XEvent *event
>    
>    	while(XtPending) {
>    	   XtNextEvent(event);
>           XtDispatchEvent(event);
>    	}
>    }
 
Should be this instead:  

   static void ProcessXInputQueue()
    {
    	XtInputMask mask;
    
    	while(mask = XtPending()) {
           XtProcessEvent(mask);
    	}
    }
  
The reason is that XtPending will return true under three cases:

1.  X event pending

2.  Timeout callback pending

3.  Alternate input callback pending.

For case 1, your loop is equivalent.  But for case 2 or 3, the call
to XtNextEvent will execute the callback and then *BLOCK* waiting for
a *REAL* x event.  Your application will appear to "freeze" until the
server generates an event.

Leo

595.4But modal boxes have their own set of problems.IO::MCCARTNEYJames T. McCartney III - DTN 381-2244 ZK02-2/N24Tue Apr 18 1989 19:389
But be aware that modal boxes will leave this artifact pasted to the root 
window that you won't be able to move out of the way. Nor will you be able 
to get anything on top of it. Thus unless you are can ensure that the user 
really wants to just sit there, I'd advise against a modal box. 

Yuch!

James 

595.5thanks..PHOBOS::WICKERTDave. DTN:321-5206Thu Apr 20 1989 10:546
    Thanks to all... got it working.  I really did want the user to
    "wait" until the processing is done.. so the modal box worked great.
    
    _-_- Dave