XSync & XFlush

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

3 posts / 0 new
Last post
XSync & XFlush

Submitted by Anonymous on Tue, 01/23/2001 - 11:34. Developers
Hi,

Does anybody can explain me the EXACT difference between XFlush and XSync.

Thanx.

Anonymous

XFlush will just flush your buffers,
while XSync will also get a reply from server,
besides flushing the buffers. It would cause
a so called "round trip". It would tend to be
slow over network, so do not do it unless you
really need it.

In my many years of X programming, I used XSync
only when programming with MIT-SHM extension,
where I would XSync before drawing something
new to my shared XImage/Pixmap, so that I could
be sure that all previous operations were finished.
Otherwise I`d get weird timing-related bugs. Which is
not strange, since two processes (my application and
X Server) would acces the same memory without any
real arbitration.

Regards

Dusan Peterc

ICS_support

dpeterc describes the essential difference, but I believe he is not quite correct on one minor point. It is true that XFlush just sends requests to the X server. This function is useful in normal application programs only when needing to flush Xlib graphics requests before doing some other operation; usually, applications are in an event loop, and XNextEvent automatically flushes. And XSync both flushes the output buffer and waits until all requests have been received and processed by the X server. There isn`t an application-level acknowledgement that the server has handled the requests, other than the function`s returning; it returns without a value, and there is no RequestsHandled event. Practically speaking, there is no difference in your application with this extra information.

Note that XSync handles the requests and generates events -- it doesn`t handle the events, of course, which you need to do in your application as part of the normal processing. This is why Xt programs, in particular, which call XSync and expect to have the screen updated don`t work properly -- the requests have gone to the X server, but the Xt program itself has not dispatched the resulting events to the appropriate widgets.

XSync is often useful in debugging, especially when a program is generating protocol errors. You can use -synchronize for an Xt program or make an explicit call to XSynchronize; you can also set _Xdebug to 1 in a debugger. Then you can set a breakpoint in the error handler to check the traceback to the offending line of code in the application -- getting the error as it occurs.

Man pages are at http//www.motifzone.com/resources/man/XFlush.html for both these functions.