[Xcb] How to wake up the GUI thread in XCB?

Cosmin Apreutesei cosmin.apreutesei at gmail.com
Sat May 23 02:58:20 PDT 2015


>> Generally if you want anything fancy (selecting on multiple file
>> descriptors, custom timeout, etc) you would
>> xcb_poll_for_queued_event()[1] until it returns NULL, then
>> xcb_get_file_descriptor() and do your own select/poll/epoll/etc.

For that I need to connect using xcb_connect_to_fd(), right? Does that
have performance implications over xcb_connect(NULL, NULL) ?

> However, this only works reliably in single-threaded code.

So, to the problem of  "xcb + timers", it looks like I have two options:

1) main thread blocked in select(xcb fd + other timer fds); other
threads must open a new connection and pass a custom message to one of
the windows if they want to wake up the main thread, as to avoid the
aforementioned problem with prefetched events.

2) Qt's way: main thread blocked in a synchronized queue; secondary
xcb thread pumping xcb messages into that queue; yet another thread
selecting on timerfds posting timer-expired events into that same
queue. Other threads can post messages into that queue too as needed.

Seems like the 2nd solution has some advantages, albeit being more
complicated: 1) allows sharing the xcb connection between threads (if
I'll ever need that); 2) no need for spawning xcb connections +
sending custom messages to wake up the main thread.

Thanks for all the help.
(and please correct me where I did the assessment wrong)


More information about the Xcb mailing list