Boost C++ Libraries: Ticket #9128: Vector deallocation with pool_allocator enters a dead loop https://svn.boost.org/trac10/ticket/9128 <p> Here is the complete test code to reproduce the bug: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;ctime&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;vector&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/pool/pool_alloc.hpp&gt;</span><span class="cp"></span> <span class="k">const</span> <span class="kt">size_t</span> <span class="n">LARGE</span><span class="o">=</span><span class="mi">200000</span><span class="p">,</span> <span class="n">LEN</span><span class="o">=</span><span class="mi">30</span><span class="p">;</span> <span class="k">template</span> <span class="o">&lt;</span> <span class="k">typename</span> <span class="n">VEC</span> <span class="o">&gt;</span> <span class="kt">void</span> <span class="n">time_it</span><span class="p">(</span> <span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">tag</span> <span class="p">)</span> <span class="p">{</span> <span class="n">VEC</span> <span class="n">vec</span><span class="p">(</span><span class="n">LARGE</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="kt">clock_t</span> <span class="n">start</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">clock</span><span class="p">()</span> <span class="p">;</span> <span class="k">for</span> <span class="p">(</span> <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span> <span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">LARGE</span> <span class="p">;</span> <span class="o">++</span><span class="n">i</span> <span class="p">)</span> <span class="n">vec</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">resize</span> <span class="p">(</span><span class="n">LEN</span><span class="p">)</span> <span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">tag</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;: &quot;</span> <span class="o">&lt;&lt;</span> <span class="p">(</span> <span class="n">std</span><span class="o">::</span><span class="n">clock</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span> <span class="p">)</span> <span class="o">/</span> <span class="kt">double</span><span class="p">(</span><span class="n">CLOCKS_PER_SEC</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; secs.</span><span class="se">\n</span><span class="s">&quot;</span> <span class="p">;</span> <span class="p">}</span> <span class="cp">#define TIME_IT( a ) time_it&lt;a&gt;( #a ) ;</span> <span class="kt">int</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span> <span class="k">typedef</span> <span class="kt">size_t</span> <span class="n">T</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="o">&gt;</span> <span class="n">std_vec</span> <span class="p">;</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">pool_allocator</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="n">boost_allocator</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span> <span class="n">boost_allocator</span><span class="o">&gt;</span> <span class="o">&gt;</span> <span class="n">boost_vec</span><span class="p">;</span> <span class="n">TIME_IT</span><span class="p">(</span> <span class="n">std_vec</span> <span class="p">)</span> <span class="p">;</span> <span class="n">TIME_IT</span><span class="p">(</span> <span class="n">boost_vec</span> <span class="p">)</span> <span class="p">;</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> 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: </p> <div class="wiki-code"><div class="code"><pre> <span class="k">while</span> <span class="p">(</span><span class="nb">true</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// if we&#39;re about to hit the end, or if we&#39;ve found where &quot;ptr&quot; goes.</span> <span class="k">if</span> <span class="p">(</span><span class="n">nextof</span><span class="p">(</span><span class="n">iter</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="o">||</span> <span class="n">std</span><span class="o">::</span><span class="n">greater</span><span class="o">&lt;</span><span class="kt">void</span> <span class="o">*&gt;</span><span class="p">()(</span><span class="n">nextof</span><span class="p">(</span><span class="n">iter</span><span class="p">),</span> <span class="n">ptr</span><span class="p">))</span> <span class="k">return</span> <span class="n">iter</span><span class="p">;</span> <span class="n">iter</span> <span class="o">=</span> <span class="n">nextof</span><span class="p">(</span><span class="n">iter</span><span class="p">);</span> <span class="p">}</span> </pre></div></div><p> 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. </p> <p> I compiled it with </p> <p> g++-4.7 -O3 -g testPool5.cc </p> <p> under Ubuntu. I tried Boost versions 1.54.0 and 1.49.0. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9128 Trac 1.4.3