Subject: assert failed in pthread_run.c
To: None <>
From: Brian Stark <>
List: current-users
Date: 02/01/2004 03:00:15

While working on one of my motif demo programs tonight I saw this error
come out of libpthread:

assertion "next != 0" failed: file
"/usr/src/lib/libpthread/pthread_run.c", line 124, function
Abort (core dumped)

I have a coredump. Here is the stack trace from gdb:

(gdb) where
#0  0x4851196b in kill () from /usr/lib/
#1  0x484d6ca6 in pthread__assertfunc () from /usr/lib/
#2  0x484d3518 in pthread__next () from /usr/lib/
#3  0x484d33fd in pthread__block () from /usr/lib/
#4  0x484d3f16 in pthread_mutex_lock () from /usr/lib/
#5  0x484d3df3 in pthread_mutex_lock () from /usr/lib/
#6  0x4856c484 in __cxa_atexit () from /usr/lib/
#7  0x4856c65b in atexit () from /usr/lib/
#8  0x0804c82e in ~AboutDialog (this=0x80724c0) at AboutDialog.C:29
#9  0x08056e70 in __tcf_4 () at callbacks.C:206
#10 0x4856c606 in __cxa_finalize () from /usr/lib/
#11 0x4856c3f6 in exit () from /usr/lib/
#12 0x0804b3ab in ___start ()

My version of pthread_run.c is:

  $NetBSD: pthread_run.c,v 1.16 2004/01/16 15:23:31 cl Exp $

I am running NetBSD 1.6ZH/i386.

Here is the relevant section from pthread_run.c:

/* Get the next thread to switch to. Will never return NULL. */
pthread__next(pthread_t self)
        pthread_t next;

        pthread_spinlock(self, &pthread__runqueue_lock);
        next = PTQ_FIRST(&pthread__runqueue);
        if (next) {
                pthread__assert(next->pt_type == PT_THREAD_NORMAL);
                PTQ_REMOVE(&pthread__runqueue, next, pt_runq);
                SDPRINTF(("(next %p) returning thread %p\n", self, next));
        } else {
                next = PTQ_FIRST(&pthread__idlequeue);
LINE 124-->     pthread__assert(next != 0);
                PTQ_REMOVE(&pthread__idlequeue, next, pt_runq);
                pthread__assert(next->pt_type == PT_THREAD_IDLE);
                SDPRINTF(("(next %p) returning idle thread %p\n", self,
        pthread_spinunlock(self, &pthread__runqueue_lock);

        return next;

Here is the relevant section from my program (showing the AboutDialog

  static const string methodName("~AboutDialog");  <-- LINE 29
  logEntryExitClass logEntryExit(fileName,__LINE__,m_className,methodName);


My test program has a dedicated thread for processing log messages (the
logEntryExitClass issues a log message in its constructor and another log
message in its destructor to trace entry/exit for the method, the
destroy() method call takes care of destroying some motif resources). I
have not run across this error message before and am not sure what to think.

Following some advice from others about PTHREAD_DIAGASSERT, I enabled some
environment variables but did not get any extra output:

assertion "next != 0" failed: file
"/usr/src/lib/libpthread/pthread_run.c", line 124, function
Abort (core dumped)

Anyone else seen this, or have a clue as to what is wrong?

Brian Stark
bpstark at pacbell dot net