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

Cosmin Apreutesei cosmin.apreutesei at gmail.com
Mon May 25 05:36:01 PDT 2015


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

Ok, guess the manual[1] needs updating then.

>> 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.
>
> Almost. XCB is fully thread-safe. You can just use the same connection from all
> of your threads. You only have to make sure that there are no other threads
> while you call xcb_disconnect().

Sure, but didn't you just said:

"However, this only works reliably in single-threaded code. When threads are
involved, another thread could cause xcb to read events from the connection and
queue them internally between your loop "until it returns NULL" and your own
select/poll/epoll."

> Main thread blocked in poll() for timer handling and all other sockets etc.
> Additionally, you include the read end of a pipe here. When you event pumping
> thread wants to wake up the main thread, it writes a byte with value 42 into the
> pipe.

Oh, so now I have to add pipes too to the mix to avoid another thread. Great :)


More information about the Xcb mailing list