[fpc-pascal] fpSelect() with very small timeout?
Graeme Geldenhuys
graemeg.lists at gmail.com
Mon Oct 20 09:57:35 CEST 2008
Hi,
Below is some code I use in fpGUI-X11's main event loop. When I played
around with multithreading, I wrote a simple application, created 4
threads that each update there own ProgressBar. I noticed that if I
don't move the mouse, the ProgressBar gets updated slowly. And when I
move the mouse over the form, the updates seem more smooth and
frequent. The default timeout for fpSelect was 1000ms. I decreased
that to 50ms and now all GUI updates from the 4 threads are smooth.
With or without moving the mouse. CPU load also doesn't seem to be
affected - it's still between 0-1% load.
Is there any downsides I don't know about when using fpSelect() with
such a small timeout?
begin
xfd := XConnectionNumber(display);
XFlush(display);
needToWait := True;
if XPending(display) > 0 then // We have a X message to process
begin
XNextEvent(display, @ev);
needToWait := False;
end;
if needToWait then // No X messages to process (we are idle). So do
a timeout wait
begin
if Assigned(FOnIdle) then
OnIdle(self);
fpFD_ZERO(rfds);
fpFD_SET(xfd, rfds);
r := fpSelect(xfd + 1, @rfds, nil, nil, 50); // 50ms timeout
if r <> 0 then // We got a X event or the timeout happened
XNextEvent(display, @ev)
else
Exit; // nothing further to do here!
end;
[... if we get here, we have X events to handle....]
end;
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
More information about the fpc-pascal
mailing list