Subject: Question regarding libpthread and a failed assertion.
To: None <current-users@netbsd.org>
From: None <netbsd99@sudog.com>
List: current-users
Date: 02/11/2003 17:10:32
I have a custom QT3.11-based application here I'm trying to port, and am 
having some weirdnesses with the pthread library as it sat at or around 1.6M 
-current as of last week.

(gdb) bt
#0  0x867dec9 in pthread__locked_switch ()
#1  0x867ab8d in pthread__block ()
#2  0x867b444 in pthread_cond_timedwait ()
#3  0x84dfc86 in QWaitCondition::wait ()
#4  0x814b267 in IOperationThread::run (this=0x8b91e70)
    at p4v/p4obj/implementation/IOperationThread.cpp:895
#5  0x82db305 in start_thread ()
#6  0x867bc5d in pthread_create ()

This is a backtrace of thread 0, while this:
#0  0x867ddc8 in pthread__switch ()
#1  0x867dc32 in pthread_spinunlock ()
#2  0x867ceb7 in pthread_mutex_unlock ()
#3  0x86b678a in malloc ()
#4  0x867cefe in pthread_mutexattr_init ()
#5  0x86b1d03 in __smutex_init ()
#6  0x86afb3e in fprintf ()
#7  0x86afcc5 in vfprintf_unlocked ()
#8  0x86afbea in vfprintf ()
#9  0x86afad4 in fprintf ()
#10 0x86923b3 in __assert13 ()
[ endless cycle starts here ]
#11 0x867acac in pthread__sched ()
#12 0x867ced1 in pthread_mutex_unlock ()
#13 0x86b678a in malloc ()
#14 0x867cefe in pthread_mutexattr_init ()
#15 0x86b1d03 in __smutex_init ()
#16 0x86afb3e in fprintf ()
#17 0x86afcc5 in vfprintf_unlocked ()
#18 0x86afbea in vfprintf ()
#19 0x86afad4 in fprintf ()
#20 0x86923b3 in __assert13 ()
[....100 of the same cycle of 9 calls....]

The assertion that appears to fail is lib/libpthread/pthread_run.c, line 135:

/* Put a thread back on the run queue */
void
pthread__sched(pthread_t self, pthread_t thread)
{

   SDPRINTF(("(sched %p) scheduling %p\n", self, thread));
   thread->pt_state = PT_STATE_RUNNABLE;
135:   assert (thread->pt_type == PT_THREAD_NORMAL);
   assert (thread->pt_spinlocks == 0);
#ifdef PTHREAD__DEBUG
   thread->rescheds++;
#endif
   pthread_spinlock(self, &pthread__runqueue_lock);  
   PTQ_INSERT_TAIL(&pthread__runqueue, thread, pt_runq);
   pthread_spinunlock(self, &pthread__runqueue_lock);
}   

There does appear to be a spinunlock() in the backtrace at the top of the 
stack.

Err..  didn't mean for this to ramble on a huge c&p session but oh well.

Any comments?

Wanted to dive into the pthread lib..  it's exciting to have it merged to 
-current!

-s