Comment 6 for bug 299152

Revision history for this message
Anton Blanchard (anton-samba) wrote :

I've been hitting this bug regularly and I agree its pretty annoying.

The synergy X11 backend claims to only make Xlib calls from the main thread:

// NOTE -- the X display is shared among several objects but is owned
// by the CXWindowsScreen. Xlib is not reentrant so we must ensure
// that no two objects can simultaneously call Xlib with the display.
// this is easy since we only make X11 calls from the main thread.

This is not true, for example we call Xflush() from multiple threads:

synergyc(CXWindowsEventQueueBuffer::flush()+0x55) synergyc(CXWindowsEventQueueBuffer::waitForEvent(double)+0x60)
synergyc(CEventQueue::getEvent(CEvent&, double)+0x157)
synergyc
synergyc(main+0x13d)

and:

synergyc(CXWindowsEventQueueBuffer::flush()+0x55)
synergyc(CXWindowsEventQueueBuffer::addEvent(unsigned int)+0x82)
synergyc(CEventQueue::addEvent(CEvent const&)+0x72)
synergyc(CTCPSocket::sendEvent(unsigned int)+0x55)
synergyc(CTCPSocket::serviceConnected(ISocketMultiplexerJob*, bool, bool, bool)+0x16f)
synergyc(TSocketMultiplexerMethodJob<CTCPSocket>::run(bool, bool, bool)+0x5b)
synergyc(CSocketMultiplexer::serviceThread(void*)+0x2d1)
synergyc(TMethodJob<CSocketMultiplexer>::run()+0x2a)
synergyc(CThread::threadFunc(void*)+0x76)
synergyc(CArchMultithreadPosix::doThreadFunc(CArchThreadImpl*)+0x50)
synergyc(CArchMultithreadPosix::threadFunc(void*)+0x42)
/lib/tls/i686/cmov/libpthread.so.0
/lib/tls/i686/cmov/libc.so.6(clone+0x5e)

I'm not an Xlib expert, but it appears that we need to call XInitThreads() if we multiple threads call into Xlib. The following patch does that, and I haven't seen the fail with it applied in a few hours (usually fails in 30 minutes).