[Xcb] questions about proper event loop and timers

Barton C Massey bart at cs.pdx.edu
Mon Aug 14 16:49:46 PDT 2006


The problem with select()ing on the XCB FD is that I'm
pretty sure you can get into races with XCB in a
multithreaded situation, and even in a single-threaded
situation you may experience false wakeups from reply data.
If you select(), then XCBPollForEvent() until no more events
are available whenever the XCB FD shows readable, it will
*probably* work, but I'm a little confused about races
between calling XCBPollForEvent(), live data arriving, and
falling back into the select().  Even if it works, I'm not
convinced that we want to *guarantee* that it will work...

It seems clear from folks' comments that XCB core or at
least Util needs to support some better I/O-multiplexing
mechanism for event-driven single-threaded programs.  Some
of us will chat offline about this RSN, and hopefully there
will also be an online conversation about what it should
be.  Good ideas appreciated.

	Bart

In message <200608141024.59657.hto at arcor.de> you wrote:
> Hi
> 
> I hit a similar problem just yesterday: Polling spikes the cpu, 
> WaitForEvent blocks everything and I don't want to open an extra 
> thread just for WaitForEvent. So:
> 
> > We could consider putting the timeout value of the select()s
> > inside XCB under user control.  I'm not very excited about
> > this, but perhaps others on the list feel differently?
> I do not think this would help too much for larger programs. I mostly 
> have a list of file descriptors which are polled with a select call. 
> When using XCBs own select call is enough, it might be a good idea to 
> allow a user defined timeout for the select.
> 
> > I would not recommend polling for events, nor trying to
> > select on the XCB connection fd.  Both of these approaches
> > have a high potential for problems, IMHO.
> I tried the last thing via XCBGetFileDescriptor. When I get the file 
> descriptor, do a select and the OS returns control to me, can I just 
> do a XCBPollForEvent then? Why do you think that doing the select 
> yourself has a high potential for problems?

> Tom
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xcb


More information about the Xcb mailing list