[Xcb] Feature Request: Function "xcb_test_for_event"

Josh Triplett josh at joshtriplett.org
Wed Apr 10 11:45:38 PDT 2013


On Wed, Apr 10, 2013 at 10:39:19AM -0700, Bart Massey wrote:
> On Tue, Apr 9, 2013 at 2:00 PM, Josh Triplett <josh at joshtriplett.org> wrote:
> >
> > Bart Massey <bart at cs.pdx.edu> wrote:
> >
> > >By now, I'm completely lost.
> > >
> > >xcb_block_until_event() is called xcb_wait_for_event() as far as I
> > >know.
> > >The non-blocking version is xcb_poll_for_event(), but it's almost
> > >always a
> > >bad idea to call it.
> >
> > xcb_wait_for_event returns the event. This new function wouldn't.
> 
> 
> I get that. It just seems kind of gratuitous. I'm not sure why I'd
> ever want to block waiting for an event I didn't need right now,  but
> if I did it would be so easy to just stash the event somewhere until
> it was needed.

The original request in this thread would disagree with that, and I can
somewhat understand its use case.  Ideally I'd rather solve that problem by
select()ing the X connection, but I don't see how to do that safely with
the semantics of X and XCB.

> > >As Josh suggests, if you want to wait on multiple things at once, spawn
> > >a
> > >blocking thread per thing, and demux the result using the usual thread
> > >mechanisms. Pipes are probably overkill here: just use a locked queue.
> > >If
> > >you use a semaphore for locking the queue, you can block until
> > >something is
> > >in it conveniently.
> >
> > Pipes help if you have a pile of other fds to wait on.
> 
> Still not getting this. It seems to me that once you admit that your
> program is multi-threaded, it's arguably better to avoid select() and
> friends altogether and just use a thread per fd with blocking reads
> and a queue. A little heavier weight, but way easier to get right and
> test and debug.

Even with all the experience I have doing and researching multithreaded
programming, I'd still always choose to use select() or poll() over any
kind of shared-memory data structure, if I have the option. :)  And if
you already have a poll() running, it seems far easier to spin off a
thread with a pipe and throw one end into the poll() than to attempt to
combine a select or poll with a shared-memory data structure.

- Josh Triplett


More information about the Xcb mailing list