libX11 and thread-safety
Jim.Gettys at hp.com
Tue Jun 7 17:48:38 PDT 2005
On Tue, 2005-06-07 at 17:41 -0600, Brian Paul wrote:
> Has anyone else experienced thread safety problems with libX11?
Yes. No surprise to me if you are having trouble.
> Specifically, I'm finding that some threaded apps that use libX11 are
> getting hung up on the ConditionWait() in _XReply().
> The apps are calling XInitThreads() as they should.
Netscape hung for years do to such problems; of course, they aggravated
this by not calling XInitThreads, IIRC.
Net result has been that few toolkits rely on the Xlib threadsafety, in
practice. Can you say what apps are hanging?
> I tried commenting-out the ConditionWait() and that seemed to solve my
> problem. Of course, that's not a proper fix.
> Just wondering if anyone else has come across anything like this or
> has any ideas.
When I originally wrote Xlib, I left some hooks for threading in the
protocol stubs, but the actual support for threading got implemented
long after me.
The Xlib threads code is horrifying, complicated, and obscure. As far as
we can tell, threads support was debugged into existence at some point,
more than designed. Keith and I studied it a while back chasing a bug
inserted by a patch someone made. While fixes to the current code base
are, of course, very welcome, the hope for long term thread safety is in
the Xcb reimplementation, which has been carefully implemented in this
area. There is little hope of maintaining the current code base in the
If anyone has fixes in their source pools, it would be good to pick them
up of course. Even there, patches will have to be looked at very
carefully, as it is difficult code: "first, do no harm".
More information about the xorg