Michael Gold wrote:
>
> > Also, the app is being fairly explicit IMO - if it does a
> > MakeCurrent when another context is already current to another thread,
> > then it's saying "I'm going multithreaded".
>
> Its too late - one thread cannot safely update the other thread's dispatch
> table to be thread-safe.
It doesn't work that way. When MakeCurrent is called we always call
pthread_set_specific() to set the thread's dispatch table pointer. It's
the fetching of the dispatch pointer that's done in a special way,
depending
on whether we're being thread safe or not.
There's a global var _glapi_Dispatch. If it's non-null it means we've
only seen one thread so far and it points to the current dispatch table.
If it's NULL, that means there is more than one thread and we must call
_glapi_get_dispatch() to get the thread's dispatch table pointer.
So, in each GL entrypoint we have code like this:
void glEnable(GLenum cap)
{
DispatchTable *d = _glapi_Dispatch ? _glapi_Dispatch :
gl_get_dispatch();
(*d->Enable)(cap);
}
This has all been implemented in Mesa 3.3 and seems to work very well.
Anyone curious about the details should download Mesa 3.3 from the
CVS repository and look at the sources.
-Brian