Xlib can deadlock when using mutlithreaded

Bug #232476 reported by Norbert Schultz
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
libx11 (Ubuntu)
Fix Released
High
Unassigned

Bug Description

When Xlib is used aggresivly in multi thread environments it can deadlock although XInitThreads is set.

Samplecode is attached. To compile use
g++ -g xlibtest.cpp -o xlibtest -lX11 -lpthread
When you run it, the program should come to no end (as it continously sends XGetGeometry messages in two threads), but here it deadlocks.

gdb output:

[Switching to thread 2 (Thread 0x4258c950 (LWP 19625))]#0 0x000000304ae0ab99 in
 pthread_cond_wait@@GLIBC_2.3.2 () from /lib/libpthread.so.0
(gdb) bt
#0 0x000000304ae0ab99 in pthread_cond_wait@@GLIBC_2.3.2 ()
   from /lib/libpthread.so.0
#1 0x000000304ca47bba in ?? () from /usr/lib/libX11.so.6
#2 0x000000304ca47fa5 in _XReply () from /usr/lib/libX11.so.6
#3 0x000000304ca254f6 in XGetGeometry () from /usr/lib/libX11.so.6
#4 0x0000000000400c71 in func (data=0x7fffef8cbcd0) at xlibtest.cpp:20
#5 0x000000304ae063f7 in start_thread () from /lib/libpthread.so.0
#6 0x000000304a2d7b2d in clone () from /lib/libc.so.6
#7 0x0000000000000000 in ?? ()
(gdb) thread 3
[Switching to thread 3 (Thread 0x42d8d950 (LWP 19626))]#0 0x000000304ae0ab99 in
 pthread_cond_wait@@GLIBC_2.3.2 () from /lib/libpthread.so.0
(gdb) bt
#0 0x000000304ae0ab99 in pthread_cond_wait@@GLIBC_2.3.2 ()
   from /lib/libpthread.so.0
#1 0x000000304ca47bba in ?? () from /usr/lib/libX11.so.6
#2 0x000000304ca47fa5 in _XReply () from /usr/lib/libX11.so.6
#3 0x000000304ca254f6 in XGetGeometry () from /usr/lib/libX11.so.6
#4 0x0000000000400c71 in func (data=0x7fffef8cbcd4) at xlibtest.cpp:20
#5 0x000000304ae063f7 in start_thread () from /lib/libpthread.so.0
#6 0x000000304a2d7b2d in clone () from /lib/libc.so.6
#7 0x0000000000000000 in ?? ()

When switching to one working thread (change num to 1 in line 29) it works.

Revision history for this message
Norbert Schultz (zaiib) wrote :
Revision history for this message
Norbert Schultz (zaiib) wrote :

Ubuntu version is 8.04 Hardy AMD64

Revision history for this message
Norbert Schultz (zaiib) wrote :

A second machine doesn't really deadlock but recognizes it...
Locking assertion failure. Backtrace:
#0 /usr/lib/libxcb-xlib.so.0 [0x7f23e804097c]
#1 /usr/lib/libxcb-xlib.so.0(xcb_xlib_unlock+0x24) [0x7f23e8040a84]
#2 /usr/lib/libX11.so.6 [0x7f23e8fa0260]
#3 /usr/lib/libX11.so.6(XGetGeometry+0x13b) [0x7f23e8f7e59b]
#4 ./xlibtest(__gxx_personality_v0+0x349) [0x400c71]
#5 /lib/libpthread.so.0 [0x7f23e8d433f7]
#6 /lib/libc.so.6(clone+0x6d) [0x7f23e8318b2d]
Locking assertion failure. Backtrace:
#0 /usr/lib/libxcb-xlib.so.0 [0x7f23e804097c]
#1 /usr/lib/libxcb-xlib.so.0(xcb_xlib_lock+0x15) [0x7f23e8040a15]
#2 /usr/lib/libX11.so.6 [0x7f23e8fa0323]
#3 /usr/lib/libX11.so.6(_XReply+0x14d) [0x7f23e8fa0f8d]
#4 /usr/lib/libX11.so.6(XGetGeometry+0x96) [0x7f23e8f7e4f6]
#5 ./xlibtest(__gxx_personality_v0+0x349) [0x400c71]
#6 /lib/libpthread.so.0 [0x7f23e8d433f7]
#7 /lib/libc.so.6(clone+0x6d) [0x7f23e8318b2d]

Revision history for this message
Bryce Harrington (bryce) wrote :

On hardy I get the following build error:

bryce@blackwold:~/Desktop$ gcc -g xlibtest.cpp -o xlibtest -lX11 -lpthread
/tmp/ccLdrI4T.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Changed in libx11:
importance: Undecided → High
status: New → Triaged
status: Triaged → New
Revision history for this message
Norbert Schultz (zaiib) wrote :

.. because it's C++ (e.g. keyword true).
gcc -g xlibtest.cpp -o xlibtest -lX11 -lpthread -lstdc++
or using g++ does compile it.

Revision history for this message
Bryce Harrington (bryce) wrote :

The locking assertion failure sounds like bug 185311.

Since we're seeing a few issues with traces involving libxcb, I've prepared a non-xcb-enabled libx11 here: http://people.ubuntu.com/~bryce/Testing/libx11/ . (I'm not certain I reverted all the deps correctly, so let me know if there are dependency-related issues with this. You probably should save your old libx11 debs in case the lack of xcb causes problems in other apps.)

Changed in libx11:
status: New → Triaged
Revision history for this message
Karol Szkudlarek (karol-mikronika) wrote :

I submitted several days ago a bug on freedesktop.org https://bugs.freedesktop.org/show_bug.cgi?id=16617 which consider similar problem. I prepared the simplest test case which
reproduce a problem with libX11 and xcb with multithreaded applications. The problem considers Ubuntu 8.04 LTS which using libXCB.

Maybe Ubuntu should consider releasing officially supported nonxcb libX11 libraries? These problem practically stops using LTS Ubuntu 8.04 with multithreaded X11 applications.

Revision history for this message
Bryce Harrington (bryce) wrote :

Hi Karol,

We did give consideration to doing this (see https://wiki.ubuntu.com/PlatformTeam/Meetings/20080701), however the issue is that with the noxcb libX11, it breaks compiz in ways that wouldn't be easy to solve. I put a bit more discussion about this onto bug 185311. You're welcome to use this package if it addresses your issue and you don't care about compiz.

Thank you for the test case though! I will forward this to the libxcb developers, and use it as an acceptance test for new libxcb/libx11 releases.

Changed in libx11:
assignee: nobody → bryceharrington
Bryce Harrington (bryce)
Changed in libx11:
assignee: bryceharrington → nobody
Revision history for this message
Karol Szkudlarek (karol-mikronika) wrote :

Hello!

I'm very interested in obtaining any information about progress of resolving "xcb" issues in Ubuntu Hardy Heron. Has anybody can simply explain me what is going on or whether anything is going on in ubuntu in this and similar xcb issues?

I saw that Interpid Ibex also have xcb linked with X11 libraries.

Regards,

Revision history for this message
Karol Szkudlarek (karol-mikronika) wrote :

Currently I'm using testing non-xcb libraries prepared by Bryce with success, but of course compiz not working. (on Hardy Heron).

Revision history for this message
zamf (cristian-zamfir) wrote :

Hi !

I am interesting in find out more about this deadlock bug, particularly, what is causing the deadlock in libX11.
I can reproduce the bug but the debug info from libX11 is missing so I cannot tell what is the cause of the bug.

Is this bug only due to libX11 code? In this case, is there an associated ticket for libX11?

I am working on a deadlock debugger that tries to reproduce deadlocks and I am particularly interested in reproducing this bug.

Thanks,
Cristi

Revision history for this message
Brian Rogers (brian-rogers) wrote :

Some important synchronization was added in libX11 version 1.2. Can this problem be reproduced with that version?

Bryce Harrington (bryce)
Changed in libx11:
status: Triaged → Incomplete
Revision history for this message
Norbert Schultz (zaiib) wrote :

At least my testcase doesn't fail anymore in Jaunty 64bit

ii libx11-dev 2:1.1.99.2-1ubuntu2 X11 client-side library (development headers)
ii libx11-xcb1 2:1.1.99.2-1ubuntu2 Xlib/XCB interface library

Revision history for this message
Jamey Sharp (sharpone) wrote :

I think the original poster's problem should have been solved with the socket-handoff rework in newer libX11/libxcb, such as the versions Norbert most recently reported success with from Jaunty. It isn't obvious to me that Karol's bug or Norbert's locking assertion failure were the same bug as the original post though. Of course the locking assertion failures are no longer detected in socket-handoff versions either, so that problem has disappeared as well.

Revision history for this message
Karol Szkudlarek (karol-mikronika) wrote :

I did testcase again and on ubuntu 8.04 LTS still hang... But on ubuntu 9.10
(i386, and amd64) seems that is OK and testcase runs correctly.
It consider https://bugs.freedesktop.org/show_bug.cgi?id=16617

Revision history for this message
Timo Aaltonen (tjaalton) wrote :

I'm closing this as fixed. Backporting the socket-handoff stuff for 8.04 is a no-go, 10.04 is behind the corner anyway..

Changed in libx11 (Ubuntu):
status: Incomplete → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.