Subject: Re: Error detected by libpthread: Invalid mutex
To: Soeren Bleikertz <soeren@openfoo.org>
From: Klaus Klein <kleink@reziprozitaet.de>
List: current-users
Date: 01/25/2004 12:23:56
On Sunday 25 January 2004 11:36, Soeren Bleikertz wrote:

> On Sat, 24 Jan 2004 21:03:16 -0800 (PST)
>
> Brian Stark <bpstark@pacbell.net> wrote:
> > Hi,
> >
> > FWIW, while running Mozilla 1.6 (from pkgsrc) on NetBSD 1.6ZH today,
> > the program died twice:
> >
> > rainforest:bstark$ mozilla
> > mozilla-bin: Error detected by libpthread: Invalid mutex.
> > Detected by file "/usr/src/lib/libpthread/pthread_mutex.c", line 312,
> > function "pthread_mutex_unlock".
> > See pthread(3) for information.
> > rainforest:bstark$ mozilla
> > mozilla-bin: Error detected by libpthread: Invalid mutex.
> > Detected by file "/usr/src/lib/libpthread/pthread_mutex.c", line 312,
> > function "pthread_mutex_unlock".
> > See pthread(3) for information.
> > rainforest:bstark$
> >
> >
> > My system was built January 16th, 2004 and my version of
> > pthread_mutex.c is:
> >
> >   $NetBSD: pthread_mutex.c,v 1.17 2003/11/24 23:54:13 cl Exp $
> >
> > The place in the file where the program died looks like this:
> >
> > int
> > pthread_mutex_unlock(pthread_mutex_t *mutex)
> > {
> >         struct mutex_private *mp;
> >         pthread_t self, blocked;
> >         int weown;
> >
> >         pthread__error(EINVAL, "Invalid mutex",
> >             mutex->ptm_magic == _PT_MUTEX_MAGIC);     <-- this is line
> > 312
> >
> > [.. remainder of function deleted for space ...]
> >
> >
> > I wasn't doing too much with Mozilla -- just browsing the Dell.com web
> > site looking for a new laptop.
> >
> > I don't see any core files, so there isn't much else to report. Anyone
> > else seen this?
> >
> > Brian Stark
> > bpstark@pacbell.net
>
> Hi, thats a problem in libpthread. Many applications aborting due to that
> libpthread function..try xmms and you see the same output. Take a look at
> bug-report: lib/24125. -soeren

Now, the definition of that interface, for non-errorcheck,
non-recursive mutexes has been saying since its finalization
in 1995: "If a thread attempts to unlock a mutex that it has not
locked or a mutex which is unlocked, undefined behavior results."
What's so hard to grasp about this?

While it's true that it you may consider it to be a problem "in"
NetBSD's libpthread that it is decidedly not tolerating blatantly
wrong use of its locking primitives,  I'd suspect that such an
application has worse problems than that.

And in a way, it does.

Note that Brian's problem is not related to the narrow lib/24125
_at all_; that PR is about unlocking mutexes already unlocked.
Brian's is about a pointer being passed to pthread_mutex_unlock()
which either references 1) a mutex previously pthread_mutex_destroy()ed,
or 2) an otherwise uninitialized/corrupted memory area.



- Klaus