Subject: Re: pthreads, Xlib and me ...
To: leon zadorin <leonleon77@gmail.com>
From: Bill Stouder-Studenmund <wrstuden@netbsd.org>
List: port-macppc
Date: 03/27/2007 17:59:06
--T7mxYSe680VjQnyC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Mar 23, 2007 at 09:34:09AM +1000, leon zadorin wrote:
> Hi all,
>=20
> well, another "i must be doing something wrong" issue...
>=20
> here is the quick sample program:
>=20
> #include <unistd.h>
> #include <pthread.h>
> #include <X11/Xlib.h>
> #include <X11/Xutil.h>
> #include <X11/Xatom.h>
>=20
> #include <GL/glx.h>
> #include <GL/gl.h>
>=20
> void * blockingThread (void *opaque)
> {
> 	Display *dpy (XOpenDisplay (NULL));
> 	if (dpy !=3D NULL)
> 	{
> 		if (glXQueryExtension(dpy, NULL, NULL))
> 		{
> 			int majorVersionNumber, minorVersionNumber;
> 			glXQueryVersion (dpy, &majorVersionNumber,=20
> 			&minorVersionNumber);
> 		}
> 	}
> 	return NULL;
> }
>=20
> int main ()
> {
> 	XInitThreads ();
> 	pthread_t blockingThreadId;
> 	pthread_create (&blockingThreadId, NULL, blockingThread, NULL);
> 	sleep (10);
>=20
> 	return 0;
> }
>=20
> Here is a rough build description
>=20
> gcc -I/usr/X11R6/include main.cc -L/usr/X11R6/lib -lGL -lX11 -lstdc++
> -lm -lpthread
>=20
> generates:
>=20
> /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

Ok, those indicate that your libX11.so may be old or that it explicitly=20
referenced old symbols.

> and at runtime:
>=20
> 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.
>=20
> 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...
>=20
> 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) ?

I know very little about X, but aren't you supposed to be calling=20
XLockDisplay at points?

Take care,

Bill

--T7mxYSe680VjQnyC
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (NetBSD)

iD8DBQFGCcvqWz+3JHUci9cRAut1AJ0VxrW7LKBz8RFcQgCNDQyfLixrvgCfRYte
cHtIwCW9tHBld9+M9EaEjoc=
=S/MN
-----END PGP SIGNATURE-----

--T7mxYSe680VjQnyC--