jww@hpfcbig.SDE.HP.COM (Jim Wichelman) (12/06/90)
Is it kosher to call the R4 version of XtMainLoop or the newer XtAppMainLoop from a callback? I believe the R2 version of XtMainLoop was non-reentrant. Please no comments about style or design, just is it OK to do? Jim Wichelman jww@hpfclp.hp.sde.com
kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) (12/08/90)
In article <9740115@hpfcbig.SDE.HP.COM> jww@hpfcbig.SDE.HP.COM (Jim Wichelman) writes: >Is it kosher to call the R4 version of XtMainLoop or the newer >XtAppMainLoop from a callback? I believe the R2 version of XtMainLoop was >non-reentrant. Six months ago I asked about toolkit reentrancy in general. MIT & Co. said that Xlib, Xt, and Xaw are not reentrant, and they have no plans for it to become so until after R5. OSF said Motif probably isn't; no statement about when it might be. -- Kaleb Keithley Jet Propulsion Labs kaleb@thyme.jpl.nasa.gov You can please all of the people some of the time,
etaylor@wilkins.iaims.bcm.tmc.edu (Eric Taylor) (12/08/90)
Use XtAppMainLoop. XtMainLoop will get you into trouble if you were using XtAppMainLoop originally. -- Eric Taylor Baylor College of Medicine etaylor@wilkins.bcm.tmc.edu (713) 798-3776
mayer@hplabsz.HPL.HP.COM (Niels Mayer) (12/08/90)
In article <1990Dec7.163323.12705@thyme.jpl.nasa.gov> kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) writes: >In article <9740115@hpfcbig.SDE.HP.COM> jww@hpfcbig.SDE.HP.COM (Jim Wichelman) writes: >>Is it kosher to call the R4 version of XtMainLoop or the newer >>XtAppMainLoop from a callback? I believe the R2 version of XtMainLoop was >>non-reentrant. > >Six months ago I asked about toolkit reentrancy in general. MIT & Co. >said that Xlib, Xt, and Xaw are not reentrant, and they have no plans >for it to become so until after R5. OSF said Motif probably isn't; no >statement about when it might be. We may be using a rather slippery definition of reentrancy here. Yes, Xlib/Xt/Xaw/Motif, etc are not reentrant in that if you have code that responds to signals or other asynch interrupts, it may screw up X. You could be processing the signal in the middle of some low level Xlib routine, which, say, grabs the server and doesn't let go.... That's why it's a good idea to either avoid signals entirely, or have them just set a flag which you later check for in your main X event loop. Although Jim Wichelman mentions "non-reentrant" in his last sentence; the first part of his question seems to do with the need for calling a nested XtMainLoop within a callback. Such nested Xt event loops are often needed if you are about to go off into a long computation within your callback, but want to post a "please wait..." message to inform the user of what's going on. Doing that will require at least a recursive call to XtDispatchEvent() (which is one of the two calls in XtAppMainLoop()). (1) e.g. for just updating a label (that is already displayed on your app): | XSync(display, 0); | while (XCheckMaskEvent(display, ExposureMask, &event)) | XtDispatchEvent(&event); (2) e.g. for popping up a Motif dialog box containing the "please wait" message: | XWindowEvent(display, window, ExposureMask, &event); | XtDispatchEvent(&event); | XSync(display, 0); (3) And in some situations that are too elaborate to go into right now, you may even need something like XtAppMainLoop(): | while(test(event)){XtAppNextEvent();XtDispatchEvent(&event);} where test is some condition that allows the nested loop to terminate. Beware of doing #3 -- it can lead to some very interesting surprises. For example, if your test(event)==true all the time, your code may just continue running within the nested event handler in the callback. (Beware of using XtAppAddWorkProc() or XtAppAddInput() in such situations).... But maybe Jim really meant "reentrant" literally, in which case, "never mind!" ------------------------------------------------------------------------------- Niels Mayer -- hplabs!mayer -- mayer@hplabs.hp.com Human-Computer Interaction Department Hewlett-Packard Laboratories Palo Alto, CA. *
meo@Dixie.Com (Miles ONeal) (12/08/90)
kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) writes: |jww@hpfcbig.SDE.HP.COM (Jim Wichelman) writes: |>Is it kosher to call the R4 version of XtMainLoop or the newer |>XtAppMainLoop from a callback? I believe the R2 version of XtMainLoop was |>non-reentrant. |Six months ago I asked about toolkit reentrancy in general. MIT & Co. |said that Xlib, Xt, and Xaw are not reentrant, and they have no plans |for it to become so until after R5. OSF said Motif probably isn't; no |statement about when it might be. Try it and see. We got away with it under R3, but it was a pain to get it working. Lots of lockups along the way... -Miles