Boost logo

Boost Users :

From: Shridhar Daithankar (shridhar_daithankar_at_[hidden])
Date: 2005-12-08 05:15:34


Hello,

I am writing a thread pool implementation and experiencing SIGSEGV in
pthread_mutex_lock under very heavy load. The crashes are repeatable and
always produce the same backtrace.

Brief description:
The threadpool creates the thread with default function objects on request.
The default function object launch a user defined function object along with
other house keeping. When done the the thread returns itself to pool of free
threads(a std::vector) for further assignment. The pool also keeps a map of
thread_id(pthread_t) to thread object so that it can signal termination to
all of the threads, busy or not.

The test has a short function object defined as
struct f2 : public pyr::threadFunction
{
        virtual void operator()(void)
        {
                int i=0;
                i++;
        }
};

It assigns the thread from pool to an object of above type in very tight loop.
It works will it attempts 600000 objects. Around 700000 objects it starts
producing segfaults.

There is no importance of either of the figure from testing point of view but
the crash is certainly not what I expect.

I stumbled upon http://lists.boost.org/boost-users/2005/04/11196.php but this
does not seem to be the case in here. But I don't know for sure if I can
trust the error checking method I have used.

Any help would be greatly appreciated.

Regards,
 Shridhar

Following are the details.

Platform: Slackware Linux 10.2, Kernel 2.6.13, GCC 3.3.6, NPTL thread library,
part of glibc-2.3.5.

The backtrace
#0 0xb7c9f1f4 in pthread_mutex_lock () from /lib/tls/libpthread.so.0
#1 0xb7d76b2f in pthread_mutex_lock () from /lib/tls/libc.so.6
#2 0xb7ed647e in boost::mutex::do_lock ()
from /usr/local/lib/libboost_thread-gcc-mt-1_33.so.1.33.0
#3 0xb7efbaa1 in pyr::threadPool::returnThreadToPool ()
   from /home/shridhar/source/shlib/libutils.1.so
#4 0xb7ef9732 in pyr::threadState::threadRunDone ()
from /home/shridhar/source/shlib/libutils.1.so
#5 0xb7ef9a6f in pyr::threadWorker::operator() ()
from /home/shridhar/source/shlib/libutils.1.so
#6 0xb7efc96c in
boost::detail::function::void_function_obj_invoker0<pyr::threadWorker,
void>::invoke ()
   from /home/shridhar/source/shlib/libutils.1.so
#7 0xb7edebfa in boost::function0<void, std::allocator<boost::function_base>
>::operator() ()
   from /usr/local/lib/libboost_thread-gcc-mt-1_33.so.1.33.0
#8 0xb7ede81f in boost::thread_group::size ()
from /usr/local/lib/libboost_thread-gcc-mt-1_33.so.1.33.0
#9 0xb7c9d0fb in start_thread () from /lib/tls/libpthread.so.0
#10 0xb7d6a99e in clone () from /lib/tls/libc.so.6

The source function
void pyr::threadPool::returnThreadToPool(const tid id)
{
        //Lock the pool so that nobody else can modify it.
        std::cout << pyr::tid() << " " << "The earth" << std::endl;
        boost::mutex::scoped_lock lock(poolmutex);
        std::cout << pyr::tid() << " " << "The stone" << std::endl;
        pyr::threadptr p = allthreads[id];
        std::cout << pyr::tid() << " " << "The carving" << std::endl;
        pool.push_back(p);
        std::cout << pyr::tid() << " " << "The step" << std::endl;
}

The error checking script:
#!/bin/bash
a=`grep "The earth" log.err |wc -l`
b=`grep "The stone" log.err |wc -l`
c=`grep "The carving" log.err |wc -l`
d=`grep "The step" log.err |wc -l`
echo "$a $b $c $d"

The results:
shridhar_at_ps0499: $ testprograms/threadpool >log.err 2>&1;error.sh
Segmentation fault
67420 67419 67419 67419
shridhar_at_ps0499: $ testprograms/threadpool >log.err 2>&1;error.sh
Segmentation fault
55222 55221 55221 55221
shridhar_at_ps0499: $ testprograms/threadpool >log.err 2>&1;error.sh
Segmentation fault
55702 55701 55701 55701
shridhar_at_ps0499: $ testprograms/threadpool >log.err 2>&1;error.sh
Segmentation fault
123284 123250 123250 123250
shridhar_at_ps0499: $ testprograms/threadpool >log.err 2>&1;error.sh
Segmentation fault
54965 54963 54963 54963
shridhar_at_ps0499: $ testprograms/threadpool >log.err 2>&1;error.sh
Segmentation fault
122436 122419 122419 122419
shridhar_at_ps0499: $ testprograms/threadpool >log.err 2>&1;error.sh
Segmentation fault
57508 57507 57507 57507


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net