Subject: pthreads, Xlib and me ...
To: None <port-macppc@netbsd.org>
From: leon zadorin <leonleon77@gmail.com>
List: port-macppc
Date: 03/23/2007 09:34:09
Hi all,
well, another "i must be doing something wrong" issue...
here is the quick sample program:
#include <unistd.h>
#include <pthread.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <GL/glx.h>
#include <GL/gl.h>
void * blockingThread (void *opaque)
{
Display *dpy (XOpenDisplay (NULL));
if (dpy != NULL)
{
if (glXQueryExtension(dpy, NULL, NULL))
{
int majorVersionNumber, minorVersionNumber;
glXQueryVersion (dpy, &majorVersionNumber, &minorVersionNumber);
}
}
return NULL;
}
int main ()
{
XInitThreads ();
pthread_t blockingThreadId;
pthread_create (&blockingThreadId, NULL, blockingThread, NULL);
sleep (10);
return 0;
}
Here is a rough build description
gcc -I/usr/X11R6/include main.cc -L/usr/X11R6/lib -lGL -lX11 -lstdc++
-lm -lpthread
generates:
/usr/X11R6/lib/libX11.so: warning: warning: reference to compatibility
socket(); include <sys/socket.h> for correct reference
/usr/X11R6/lib/libX11.so: warning: warning: reference to compatibility
__stat13(); include <sys/stat.h> to generate correct reference
/usr/X11R6/lib/libX11.so: warning: warning: reference to compatibility
__fstat13(); include <sys/stat.h> to generate correct reference
and at runtime:
a.out: Error detected by libpthread: Unlocking unlocked mutex.
Detected by file "/usr/src/lib/libpthread/pthread_mutex.c", line 369,
function "pthread_mutex_unlock".
See pthread(3) for information.
I have noticed that I am not closing the X display in this sample
code... but don't think this is the cause of the problem (in the
actual app there is a correspording XCloseDisplay call) - I shall try
this sample code with XCloseDisplay as well... - not near my NetBSD
box, as currently I rarely get a chance to play with it...
Can anyone out there reproduce the "unlocking unlocked mutex" error
(in my case, I can get rid of it if I take out "XInitThreads" but in
practice (my app) the "XInitThreads" needs to remain) ?