[Xcb] problem with xcb-based Xlib and multithreaded applications

Uli Schlachter psychon at znc.in
Tue Jan 4 03:05:57 PST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi,

Am 04.01.2011 11:25, Francesco Abbate wrote:
> My application adopt a simple scheme to avoid collisions between
> threads or race conditions. A lock per window is used, only one thread
> polls and treats the incoming events. Other secondary threads can
> perform drawing operations on the same window but the locks ensures
> that such operations are performed only when the main thread is
> waiting for events in a XNextEvent calls. I precise that I call
> XInitThreads before opening any connections.

Uhm, what do you need threads for? Only one thread can be active at any given
time with such a looking scheme, no?

> When the xcb-based implementation of libX11 was introduced my
> applications began to hang. After investigations it was clear that the
> problem was coming from the xcb implementation of X11 that does not
> tolerate that a second thread perform drawing requests when another
> threads is polling the events using the same connection.

attached is an ugly (e.g. drawing without getting an Expose) test case. The main
thread just does XNextEvent and prints all events while a thread does some
drawing via XFillRectangle every second. My libX11 uses xcb:

$ ldd /usr/lib/libX11.so | grep xcb
	libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f5b9b3ac000)

However, I don't see any hangs from this. It all seems to work fine. What am I
doing wrong that makes this work correctly?

Cheers,
Uli

- -- 
The Angels have the phone box!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBCAAGBQJNIv8RAAoJECLkKOvLj8sG61wH/RGgFqx18Tb0Cwqx1K7qFOUv
6aVzaQwj5n7WI1F4EZ8TTIYn9XrWoxQ2kfc0/lUgxqvFW0CrQyQpnbCNhBrZaQcN
rVb4zfhkQF13ZMpz/y4pcBzDxXzLKn5IFf1YSKTcjW3I75/gYmagB0SK9Uj8A+E8
NFEU+7YnLaijWF1h+vsuj0OyH4UCCHpDqfIE7SbtrYU4mHvoRDPwqtlfh/fdrlnU
YX3LyFLQKVjZVODCy5B+r+FpFPwi72/XqOp0R+txilDpNG8QaywCVeSh+y+UL95V
rdNXPBDyTNn93VeT1c46sYw64YGB82HmMgpqaN69h9lS6aeaSdR9072flEZZFpg=
=OcPl
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.c
Type: text/x-csrc
Size: 1598 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20110104/0eecfe81/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.c.sig
Type: application/octet-stream
Size: 287 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20110104/0eecfe81/attachment.obj>


More information about the Xcb mailing list