Forgive me for chiming in late, I was hoping that the archive search
of WineHQ would refresh my memory about the discussion of
Ove's pthread patch. Please bear with my lack of a complete
grasp of the technical details, and please forgive me for rehashing
a discussion that is already well understood by some.
However, this seems to be a very important issue to me.
I tried to understand exactly what the problem was if we linked
Wine with X 4.0, libpthread, and OpenGL. Really, the core issue
is why we can't link in libpthread.
To rehash what is already known:
After a scan of the glibc 2.1 source code (and no experimental evidence
whatsoever), I found only the following two problems:
1. malloc and free will fail badly
I see two issues. First, the code for malloc tests to see if
__pthread_initialize is
available. If so, it invokes it. I believe that __pthread_initialize will
actually run correctly, and start the pthread_manager. I have no proof of
this.
Second, as malloc and free manipulate internal structures, they
rely on macros from malloc-t.h. The ones I inspected were
mutex_init, mutex_lock, et. all. Basically, if libpthread is linked in,
and the weak symbols for __pthread_mutex_xxx are available,
then malloc will use them, otherwise they turn into NOPs
(and malloc is presumably running in a single thread environment).
However, in our case, the code for pthread_mutex_lock will be invoked.
That code, in turn, grabs the pthread_self descriptor from the GS
register. Of course, we're not really a pthread and *boom* down she
goes.
2. errno will fail
Again, same basic issue.
However, I found no further instances where glibc examines the weak
aliasing on the pthread functions. Of course, I did not look at the
source code for X 4.0 or any other library to see in what ways it
depends on the weak aliasing of pthreads.
As I understand Ove's pthread patch, his patch resolves this problem.
I don't have his patch in front of me, but I believe he did this by
registering Wine threads with libpthread (setting up the GS register),
and by correspondingly trapping the creation of threads from
libpthread and registering them with Wine.
So, my basic question is:
What is wrong with Ove's patch, and why can't it be part of the
main Wine release? Further, what work do we need to do in order
to resolve this problem for the Wine mainstream? Do we need
changes to glibc? It seems like the problem areas are small enough
in scope (malloc and errno) that we ought to be able to create
a lasting solution.
Thanks for listening,
Jeremy