[Xcb] How to wake up the GUI thread in XCB?
Uli Schlachter
psychon at znc.in
Mon May 25 05:42:20 PDT 2015
Am 25.05.2015 um 14:36 schrieb Cosmin Apreutesei:
>>> 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.
Uhm, which "[1]"?
>>> 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."
Well, yes. And I guess I now understood your idea. Sorry for missing that earlier.
You use a new xcb connection so that your calls into xcb cannot cause events to
be read. That way (using one connection per thread) you avoid the race.
This does indeed work.
>> 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 :)
Eventfd works, too. ;-)
Uli
--
“Some people are worth melting for.” - Olaf
More information about the Xcb
mailing list