Opened 9 years ago

#9128 new Bugs

Vector deallocation with pool_allocator enters a dead loop

Reported by: Dragan Vidovic <vitkecar@…> Owned by: Chris Newbold
Milestone: To Be Determined Component: pool
Version: Boost 1.54.0 Severity: Showstopper
Keywords: Cc:

Description

Here is the complete test code to reproduce the bug:

#include <ctime>
#include <iostream>
#include <vector>
#include <boost/pool/pool_alloc.hpp>

const size_t LARGE=200000, LEN=30;

template < typename VEC > void time_it( const char* tag )
{
   VEC vec(LARGE);

   std::clock_t start = std::clock() ;
   for ( int i = 0 ; i < LARGE ; ++i ) vec[i].resize (LEN) ;
   std::cout << tag << ": " << ( std::clock() - start ) /
      double(CLOCKS_PER_SEC) << " secs.\n" ;
}

#define TIME_IT( a ) time_it<a>( #a ) ;

int main()
{
   typedef size_t T;
   typedef std::vector<std::vector<T> > std_vec ;

   typedef boost::pool_allocator<T> boost_allocator;
   typedef std::vector<std::vector<T, boost_allocator> > boost_vec;

   TIME_IT( std_vec ) ;
   TIME_IT( boost_vec ) ;
   return 0;
}

It hangs while cleaning up at the end of the time_it function. I've seen with ddd that it hangs in boost/pool/simple_segregated_storage.hpp in the following block:

  while (true)
  {
    // if we're about to hit the end, or if we've found where "ptr" goes.
    if (nextof(iter) == 0 || std::greater<void *>()(nextof(iter), ptr))
      return iter;

    iter = nextof(iter);
  }

If instead of pool_allocator I use fast_pool_allocator then this does not happen and it's equally slow. In this example pool_allocator takes about 4-5 times longer to allocate than the default one - I don't know why.

I compiled it with

g++-4.7 -O3 -g testPool5.cc

under Ubuntu. I tried Boost versions 1.54.0 and 1.49.0.

Change History (0)

Note: See TracTickets for help on using tickets.