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

Uli Schlachter psychon at znc.in
Tue Jan 4 10:06:25 PST 2011


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

Am 04.01.2011 17:29, Francesco Abbate wrote:
> 2011/1/4 Uli Schlachter <psychon at znc.in>:
>> I just made this use XSync(d, True) and managed to make this hang (it worked for
>> a moment at first). Don't ask me how I managed to do this, it didn't hang on the
>> second try.
>> Then I removed all the "sleep(1);" which makes it freeze almost immediately,
>> even with Discard=False.
> 
> Thank you Uli, we have easily obtained a perfect test case for this bug :-)

This is getting off-topic, does someone know the right mailing list for this and
can forward it?


I spent the better half of an afternoon starring at libX11's code. Here is what
happens (src/xcb_io.c in libX11, around line 187)

unsigned long event_sequence = dpy->last_request_read;
if(event)
    widen(&event_sequence, event->full_sequence);

The second threads does lots of GetInputFocus requests. By the time an event
comes in, dpy->last_request_read is way beyond the event's sequence number
because of the second thread.

E.g. I was seeing dpy->last_request_read = 0x3ab and
event_sequence = event->full_sequence = 0x121

widen() then turns this into event_sequence = 0x100000121. Because obviously
0x100000121 > 0x3ab, this code goes into a busy loop.

Just removing the call to widen() makes the hang go away for me. Since it
depends on sizeof(unsigned long) > 32, I guess that this only happens on 64bit
systems.
However, removing widen() will make this hang on 32bit sequence number wraps.
Perhaps someone will come up with a good idea to solve this.

Cheers,
Uli

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

iQEcBAEBCAAGBQJNI2GdAAoJECLkKOvLj8sGoZsIAMGKk81U0zNVLT5+VvDWKvUj
jfqLlV+VQWA+RSoO2hl187zWOt7nTZOKG51RY11efLGHthN854jLskz0COrX57oO
YUETKNqcUuBrqyXM5/3tAgI8G9/Jn9OsjN6ggsZXqpkfY6W1dMu0nUh3287sH39g
aGhPzDRlJ4cC6ovpNryYmERYqOpG4UNvpA291pOGWTVBR1NM/98yAp1tgQHhnwo4
ITq2e6gpZzu6IF/Z7g/L8ij0e68A1geBJfT0Ym9YzsQhJHf8SklIi988rUP7jnED
5eKlnwaPvZgIpRLA0LZW5acEYgyMqlfLiA9pxlxCVp0KYijyaIBnE31Fr58MCR4=
=rwnp
-----END PGP SIGNATURE-----


More information about the Xcb mailing list