Boost C++ Libraries: Ticket #2869: pool_allocator interferes with multi-layer instantiations https://svn.boost.org/trac10/ticket/2869 <p> Using <strong>pool_allocator</strong> with multiple layers of data causes misordered construction/destruction. </p> <h2 class="section" id="Test1">Test 1</h2> <p> In the example below, the problem is with construction. I was trying to reproduce a problem with destruction of static STL containers; however, the construction problem is the one that surfaced. </p> <pre class="wiki">#include &lt;vector&gt; #include &lt;boost/pool/pool_alloc.hpp&gt; #include &lt;stdio.h&gt; template &lt;class Type&gt; struct container_spec { typedef std::vector &lt;Type, boost::pool_allocator &lt;Type&gt; &gt; type; }; typedef container_spec &lt;int&gt; ::type int_vector; typedef container_spec &lt;int_vector&gt; ::type int_array; int main() { int_array array_of_int; for (int I = 0; I &lt; 10; I++) { array_of_int.push_back( int_vector() ); for (int J = 0; J &lt; 10; J++) array_of_int[I].push_back(I * J); } fprintf(stderr, "vectors filled\n"); //&lt;-- never seen fflush(stderr); } </pre><p> <strong>gdb</strong> backtrace is as follows: </p> <pre class="wiki">Starting program: [...]/a.out Program received signal SIGSEGV, Segmentation fault. 0x00000000004021aa in boost::simple_segregated_storage&lt;unsigned long&gt;::segregate (block=0x608330, sz=0, partition_sz=8, end=0x608338) at ./boost/pool/simple_segregated_storage.hpp:207 207 nextof(iter) = old; (gdb) bt #0 0x00000000004021aa in boost::simple_segregated_storage&lt;unsigned long&gt;::segregate (block=0x608330, sz=0, partition_sz=8, end=0x608338) at ./boost/pool/simple_segregated_storage.hpp:207 #1 0x0000000000402218 in boost::simple_segregated_storage&lt;unsigned long&gt;::add_block (this=0x607568, block=0x608330, nsz=0, npartition_sz=8) at ./boost/pool/simple_segregated_storage.hpp:72 #2 0x0000000000402444 in boost::simple_segregated_storage&lt;unsigned long&gt;::add_ordered_block (this=0x607568, block=0x608330, nsz=0, npartition_sz=8) at ./boost/pool/simple_segregated_storage.hpp:89 #3 0x00000000004024af in boost::simple_segregated_storage&lt;unsigned long&gt;::ordered_free_n (this=0x607568, chunks=0x608330, n=0, partition_size=8) at ./boost/pool/simple_segregated_storage.hpp:159 #4 0x0000000000402532 in boost::pool&lt;boost::default_user_allocator_new_delete&gt;::ordered_free (this=0x607568, chunks=0x608330, n=0) at ./boost/pool/pool.hpp:270 #5 0x0000000000402951 in boost::singleton_pool&lt;boost::pool_allocator_tag, 4u, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt;::ordered_free (ptr=0x608330, n=0) at ./boost/pool/singleton_pool.hpp:101 #6 0x0000000000402979 in boost::pool_allocator&lt;int, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt;::deallocate (ptr=0x608330, n=0) at ./boost/pool/pool_alloc.hpp:125 #7 0x00000000004029a4 in std::_Vector_base&lt;int, boost::pool_allocator&lt;int, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt; &gt;::_M_deallocate (this=0x608010, __p=0x608330, __n=0) at /usr/include/c++/4.2/bits/stl_vector.h:134 #8 0x0000000000404400 in std::vector&lt;int, boost::pool_allocator&lt;int, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt; &gt;::_M_insert_aux (this=0x608010, __position={_M_current = 0x608330}, __x=@0x7fff5b23c7a0) at /usr/include/c++/4.2/bits/vector.tcc:295 #9 0x000000000040449d in std::vector&lt;int, boost::pool_allocator&lt;int, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt; &gt;::push_back (this=0x608010, __x=@0x7fff5b23c7a0) at /usr/include/c++/4.2/bits/stl_vector.h:605 #10 0x0000000000401313 in main () at test.cpp:27 </pre><h2 class="section" id="Test2">Test 2</h2> <p> The code below results in destruction errors, but not construction errors. </p> <pre class="wiki">#include &lt;vector&gt; #include &lt;boost/pool/pool_alloc.hpp&gt; #include &lt;stdio.h&gt; template &lt;class Type&gt; struct container_spec { typedef std::vector &lt;Type, boost::pool_allocator &lt;Type&gt; &gt; type; }; typedef container_spec &lt;int&gt; ::type int_vector; typedef container_spec &lt;int_vector&gt; ::type int_array; int main() { int_array array_of_int; array_of_int.push_back( int_vector() ); fprintf(stderr, "vector added\n"); //&lt;-- shows up fflush(stderr); } </pre><p> <strong>gdb</strong> backtrace is as follows: </p> <pre class="wiki">Starting program: [...]/a.out vector added Program received signal SIGSEGV, Segmentation fault. 0x000000000040210a in boost::simple_segregated_storage&lt;unsigned long&gt;::segregate (block=0x607330, sz=0, partition_sz=8, end=0x607338) at ./boost/pool/simple_segregated_storage.hpp:207 207 nextof(iter) = old; (gdb) bt #0 0x000000000040210a in boost::simple_segregated_storage&lt;unsigned long&gt;::segregate (block=0x607330, sz=0, partition_sz=8, end=0x607338) at ./boost/pool/simple_segregated_storage.hpp:207 #1 0x00000000004023cf in boost::simple_segregated_storage&lt;unsigned long&gt;::add_ordered_block (this=0x606e48, block=0x607330, nsz=0, npartition_sz=8) at ./boost/pool/simple_segregated_storage.hpp:91 #2 0x000000000040240f in boost::simple_segregated_storage&lt;unsigned long&gt;::ordered_free_n (this=0x606e48, chunks=0x607330, n=0, partition_size=8) at ./boost/pool/simple_segregated_storage.hpp:159 #3 0x0000000000402492 in boost::pool&lt;boost::default_user_allocator_new_delete&gt;::ordered_free (this=0x606e48, chunks=0x607330, n=0) at ./boost/pool/pool.hpp:270 #4 0x00000000004028b1 in boost::singleton_pool&lt;boost::pool_allocator_tag, 4u, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt;::ordered_free (ptr=0x607330, n=0) at ./boost/pool/singleton_pool.hpp:101 #5 0x00000000004028d9 in boost::pool_allocator&lt;int, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt;::deallocate (ptr=0x607330, n=0) at ./boost/pool/pool_alloc.hpp:125 #6 0x0000000000402904 in std::_Vector_base&lt;int, boost::pool_allocator&lt;int, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt; &gt;::_M_deallocate (this=0x607010, __p=0x607330, __n=0) at /usr/include/c++/4.2/bits/stl_vector.h:134 #7 0x0000000000402944 in ~_Vector_base (this=0x607010) at /usr/include/c++/4.2/bits/stl_vector.h:120 #8 0x000000000040297f in ~vector (this=0x607010) at /usr/include/c++/4.2/bits/stl_vector.h:268 #9 0x0000000000402997 in boost::pool_allocator&lt;std::vector&lt;int, boost::pool_allocator&lt;int, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt; &gt;, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt;::destroy ( ptr=0x607010) at ./boost/pool/pool_alloc.hpp:99 #10 0x00000000004029b5 in std::_Destroy&lt;std::vector&lt;int, boost::pool_allocator&lt;int, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt; &gt;*, boost::pool_allocator&lt;std::vector&lt;int, boost::pool_allocator&lt;int, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt; &gt;, boost::default_user_allocator_new_delete, boost::details::pool::pthread_mutex, 32u&gt; &gt; ( __first=0x607010, __last=0x607028, __alloc={static next_size = &lt;optimized out&gt;}) at /usr/include/c++/4.2/bits/stl_construct.h:174 #11 0x0000000000402ad8 in ~vector (this=0x7fff34cb2200) at /usr/include/c++/4.2/bits/stl_vector.h:268 #12 0x000000000040130e in main () at test.cpp:25 </pre><p> In other circumstances of the same pattern these aren't a problem (too complex to post, but still a vector of vectors using <strong>pool_allocator</strong>.) </p> <p> Partial source tree exported from <a class="ext-link" href="http://svn.boost.org/svn/boost/trunk/boost/"><span class="icon">​</span>http://svn.boost.org/svn/boost/trunk/boost/</a> <em>Mon Mar 16 21:33:09 EDT 2009</em>, didn't record the revision number. </p> <p> Kevin P. Barry </p> <pre class="wiki">&gt; g++ -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu3) </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2869 Trac 1.4.3 Steven Watanabe Thu, 19 Mar 2009 17:58:00 GMT <link>https://svn.boost.org/trac10/ticket/2869#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2869#comment:1</guid> <description> <p> Here's a reduced form of the problem: </p> <pre class="wiki">#include &lt;boost/pool/pool_alloc.hpp&gt; int main() { boost::pool_allocator&lt;int&gt; alloc; int* p = alloc.allocate(0); alloc.deallocate(p, 0); } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Fri, 05 Jun 2009 00:15:25 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2869#comment:2 https://svn.boost.org/trac10/ticket/2869#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> </ul> <p> Duplicates <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/386" title="#386: Bugs: boost::pool_allocator breaks with vector of vectors (closed: fixed)">#386</a>. </p> Ticket