BACKGROUND PROCESSING

An application's interface should always remain as responsive to a user as possible. This requires that:

There are several possible ways to do background processing:

Xt is event driven, not interrupt driven. No background processing, whether it be a workproc, a timeout routine, or just ordinary code, will be interrupted by X. If the background processing really must run a long time, then it should voluntarily relinquish control from time to time to ensure that events get serviced frequently. If it does not do so, processing user input will be delayed.

If you are using either workproc(s) or timeout routine(s), and if no one of them is longer than a small fraction of a second long, then event handling will be responsive without taking any special action.

Keeping a application responsive, even if needs time-consuming background processing, need not be too restrictive. It just means that the background processing must be properly structured. One way to think of this is that is is the reverse of the usual -- instead of relying on Xt to call the application from time to time for a little processing, the application calls Xt from time to time to let Xt do a little processing. There are several ways this can be done:

OVERVIEW OF WORKPROC'S

POLLING FOR EVENTS

Long-running background tasks should poll for, and process, events. At a minimum, the process should honor expose events. If expose events are all that is being processed, the application should put up a busy cursor.

Following is a code sample that will poll for and process all events. Note that if you are in a callback and there is a pending event that would trigger the callback, you will get re-entered. If you are in a timeout routine and another timer for that routine has gone off, you will also get re-entered. Your application is responsible for handling such a case. Of course, you can avoid the problem by keeping your callbacks and timeout routines short enough that polling is not necessary.


        while (XtAppPending(appContext))
            XtAppProcessEvent(appContext, XtIMAll);

The manual pages describe these functions and their parameters in more detail. You can do such things as process only specific events. This document is only an overview. For details, read the appropriate sections from the following references:


* "X WINDOW SYSTEM TOOLKIT", by Asente & Swick
      PART I PROGRAMMER'S GUIDE
	section 6.8 "Getting Events"
		6.9 "Dispatching Events"
		6.10 "Custom Event-Dispatching Loops"
		6.11 "Background Work Procedures"
		6.11 "Using Xlib Event Routines"
      PART II SPECIFICATION
	section 7.4 "Querying Event Sources"
		7.5 "Dispatching Events"
		7.6 "The Application Input Loop"
		7.8 "Adding Background Work Procedures"

* "X Toolkit Intrinsics Programming Manual, OSF/Motif 1.2
      Edition", (O'Reilly Vol 4)
	section 9.6 "Work Procedures"

* "X Toolkit Intrinsics Reference Manual", (O'Reilly Vol 5)
		XtWorkProc
		XtAppAddWorkProc()
		XtRemoveWorkProc()
		XtAppPending()
		XtAppNextEvent()
		XtAppProcessEvent()

* "Motif Programming Manual" (O'Reilly Vol 6)
	section 20.2   "Working Dialogs"
		20.2.1 "Using Work Procedures"
		20.2.2 "Using Timers"
		20.2.3 "Processing Events Yourself"

* "The X Window System, Programming and Applications with Xt,
      OSF/Motif Edition", by Doug Young
	section 5.7 "USING WORKPROCS"

NON_TOOLKIT X PERFORMANCE NOTES

BACKING STORE and SAVE UNDER

Backing store and save under are intended as performance optimizations. In practice, using them may instead lead to performance degradation.

Backing store and save under for non-GL windows

Backing store and save under for non-GL windows