Boost logo

Boost Users :

From: Labour, Matthieu (MLPRO SF) (matthieu_labour_at_[hidden])
Date: 2005-08-09 18:18:21


Caleb

Thanks for your answer.
I tried running the following program with valgrind but as you said
valgrind doesn't complain and I was unable to crash it.
Without valgrind sometimes it works fine, sometimes it crashes....
I tested it on 4 different machines. On all of them I had crashes. So I
doubt the memory is at fault.
Sometimes it requires 20+ threads to crash it. But it crashes always at
the same place.
Here is an example of simple program + purify trace.

I use Red Hat linux 3.2.3-47
Gcc version 3.2.3 20030502
Purify 2003a.05.15
Boost 1.32.0

#include <stdlib.h>
#include <iostream>

#include <boost/thread/thread.hpp>

#include <boost/pool/poolfwd.hpp>
#include <boost/pool/object_pool.hpp>

class Foo{
public:
        int foo;
};

static boost::object_pool<Foo>* _pool;

class Bar{
public:
        Bar(){}
        void operator()(){
                const int FOO_COUNT = 100;
                Foo* foo[FOO_COUNT];
                int i;
                
                for(;;){
                        for(i=0; i<FOO_COUNT; i++){
                                try{
                                foo[i] = _pool->construct();
                                }catch(...){
                                        std::cout <<
"exception:construct..." << std::endl;
                                }
                        }
                        
                        for(i=0; i<FOO_COUNT; i++)
                                if (foo[i]){
                                try{
                                        _pool->destroy(foo[i]);
                                        }catch(...){
                                        std::cout <<
"exception:destroy..." << std::endl;
                                        }
                                        
                                }

                }
        }
};

int main(int argc, char* argv[])
{

        if(argc != 2){
                std::cout << "Usage: nbThrd" << std::endl;
                return 0;
        }
        
        int nbThrd = atoi(argv[1]);

        _pool = new boost::object_pool<Foo>(10);

        boost::thread_group _threads;
        Bar bar;

        for (int i=0; i<nbThrd; ++i){
                _threads.create_thread(bar);
        }

        
        _threads.join_all();
        
        return 0;
}

**** Purify instrumented custom (pid 23146 at Tue Aug 9 18:13:32 2005)
  * Purify 2003a.06.15 Linux (32-bit) (c) Copyright IBM Corp. 1992, 2005
All rights reserved.
  * For contact information type: "purify -help"
  * For TTY output, use the option "-windows=no"
  * Command-line: custom 50
  * Options settings: -g++=yes -purify -best-effort \
    -cache-dir=/home/mlabour/tmp-mlabour-g++ -chain-length=20 \
    -fds-inuse-at-exit=no -inuse-at-exit -max_threads=100 \
 
-purify-home=/tools/rational/2003a.06.15/releases/purify.i386_linux2.200
3a.06.15 \
    -gcc3_path=/usr/bin/g++ -cache-dir=/home/mlabour/tmp-mlabour-g++ \
    -hw_cap=yes -language=english
  * License successfully checked out.
  * Command-line: custom 50

**** Purify instrumented custom (pid 23146) ****
MAF: Memory allocation failed (3 times):
  * This is occurring while in thread 27610032:
        malloc [rtlib.o]
        _ZnWjRkSt9nOtHrOw_t [libstdc++.so.5]
        operator new []( unsigned,std::nothrow_t const &)
[libstdc++.so.5]
        
boost::pool<boost::default_user_allocator_new_delete>::ordered_malloc_ne
ed_resize( void) [pool.hpp:55]
        
boost::object_pool<Foo,boost::default_user_allocator_new_delete>::constr
uct( void) [object_pool.hpp:76]
        Bar::operator ()( void) [custom.cpp:27]
        boost::detail::function::void_function_obj_invoker0<Bar,
void>::invoke(boost::detail::function::any_pointer)
[function_template.hpp:128]
        boost::function0<
void,std::allocator<boost::function_base>>::operator ()( void) const
[function_template.hpp:581]
        thread_proxy [thread.cpp:113]
        start_thread [libpthread.so.0]
        clone [libc.so.6]
  * Attempt to allocate 335544328 bytes failed.

**** Purify instrumented custom (pid 23146) ****
COR: Fatal core dump:
  * This is occurring while in thread 1073758112:
        arena_get2 [libc.so.6]
        MaLlOc [libc.so.6]
        _dl_allocate_tls []
        allocate_stack [libpthread.so.0]
        PtHrEaD_CrEaTe@@GlIbC_2.1 [libpthread.so.0]
        boost::thread::thread(boost::function0<
void,std::allocator<boost::function_base>> const &) [thread.cpp:161]
        boost::thread_group::create_thread(boost::function0<
void,std::allocator<boost::function_base>> const &) [thread.cpp:327]
        main [function_template.hpp:433]
        __libc_start_main [libc.so.6]
        _start [crt1.o]
  * Received signal 11 (SIGSEGV - Segmentation fault)
  * Handler function: SIG_DFL
  * Faulting address = 0x40b5e008
  * Signal mask: (SIGHUP | SIGQUIT | SIGILL | SIGABRT | SIGBUS | \
    SIGKILL | SIGSEGV | SIGALRM | SIGTERM | SIGCHLD | SIGSTOP | SIGSTP |
\
    SIGTTOU | SIGXFSZ | SIGVTALRM | SIGPWR | SIGUNUSED | SIGReserved35 |
\
    SIGReserved36 | SIGReserved38 | SIGReserved39 | SIGReserved42 | \
    SIGReserved43 | SIGReserved44 | SIGReserved46 | SIGReserved47 | \
    SIGReserved53 | SIGReserved54 | SIGReserved57 | SIGReserved58 | \
    SIGReserved61 | SIGReserved62)
  * Pending signals:

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Caleb Epstein
Sent: Tuesday, August 09, 2005 8:32 AM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] Maybe a problem with boost::object_pool?

On 8/8/05, Labour, Matthieu (MLPRO SF) <matthieu_labour_at_[hidden]> wrote:

> A program creates N threads that construct & destroy objects in an
> object pool. With N = 9, it crashes on linux

That program works fine here with 1, 2, 4, 8, and 9 threads on a 2-way
RedHat AS3.1 machine here. I've tried running it with "valgrind" and
I don't get any errors.

You might try running a memory test on your PC like memtest86.
Perhaps you have bad RAM.

-- 
Caleb Epstein
caleb dot epstein at gmail dot com
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
--------------------------------------------------------
If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Click here for important additional terms relating to this e-mail.     http://www.ml.com/email_terms/
--------------------------------------------------------

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