Boost C++ Libraries: Ticket #10469: Erasing from intrusive unordered_multiset with optimize_multikey goes into an infinite loop https://svn.boost.org/trac10/ticket/10469 <p> I create an intrusive unordered_multiset and insert multiple elements with the same key into it. When I try to erase an element through an iterator, like so: </p> <pre class="wiki">ms.erase(ms.iterator_to(elem)); </pre><p> , the erase function never returns. </p> <p> I use Microsoft Visual Studio 2010. Ran into this problem with boost 1.51, and verified that it still exists in 1.56. Same code seems to run fine with optimize_multikey&lt;false&gt;. Here's the complete code: </p> <pre class="wiki">#include &lt;boost/intrusive/unordered_set.hpp&gt; #include &lt;iostream&gt; using namespace boost::intrusive; //------------------------------------------------------------------------ struct MyClass { typedef unordered_set_member_hook&lt;optimize_multikey&lt;true&gt; &gt; MultisetHook; int id_; int key_; MultisetHook byKeyHook_; friend bool operator== (const MyClass &amp;lhs, const MyClass &amp;rhs) { return lhs.key_ == rhs.key_; } friend std::size_t hash_value(const MyClass &amp;v) { return std::size_t(v.key_); } }; //------------------------------------------------------------------------ typedef member_hook&lt; MyClass, MyClass::MultisetHook, &amp;MyClass::byKeyHook_&gt; MyHook; typedef unordered_multiset&lt;MyClass, MyHook&gt; Multiset; //------------------------------------------------------------------------ size_t const NUM_BUCKETS = 32; size_t const NUM_RECS = 10; //------------------------------------------------------------------------ int main(int argc, char* argv[]) { Multiset::bucket_type buckets[NUM_BUCKETS]; Multiset ms(Multiset::bucket_traits(buckets, NUM_BUCKETS)); MyClass recs[NUM_RECS]; for (size_t i = 0; i != NUM_RECS; ++i) { MyClass &amp; rec = recs[i]; rec.id_ = i; rec.key_ = i &lt; 6 ? 123 : 456; ms.insert(rec); } std::cerr &lt;&lt; "--- before erase ---\n"; for (auto it = ms.begin(), endIt = ms.end(); it != endIt; ++it) { std::cerr &lt;&lt; "rec " &lt;&lt; it-&gt;id_ &lt;&lt; " key=" &lt;&lt; it-&gt;key_ &lt;&lt; std::endl; } { MyClass &amp; rec = recs[4]; std::cerr &lt;&lt; "--- erasing rec " &lt;&lt; rec.id_ &lt;&lt; " ---\n"; // Stuck in the following erase ms.erase(ms.iterator_to(rec)); } std::cerr &lt;&lt; "--- after erase ---\n"; for (auto it = ms.begin(), endIt = ms.end(); it != endIt; ++it) { std::cerr &lt;&lt; "rec " &lt;&lt; it-&gt;id_ &lt;&lt; " key=" &lt;&lt; it-&gt;key_ &lt;&lt; std::endl; } return 0; } </pre><p> And here's the output: </p> <pre class="wiki">--- before erase --- rec 6 key=456 rec 9 key=456 rec 8 key=456 rec 7 key=456 rec 0 key=123 rec 5 key=123 rec 4 key=123 rec 3 key=123 rec 2 key=123 rec 1 key=123 --- erasing rec 4 --- </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10469 Trac 1.4.3 Ion Gaztañaga Tue, 30 Sep 2014 22:08:50 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10469#comment:1 https://svn.boost.org/trac10/ticket/10469#comment:1 <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">fixed</span> </li> </ul> <p> Thanks for the report, there was a bug when inserting elements. Fixed in: </p> <p> [develop 702ae47] Fixed <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/10469" title="#10469: Bugs: Erasing from intrusive unordered_multiset with optimize_multikey goes ... (closed: fixed)">#10469</a>: Erasing from intrusive unordered_multiset with optimize_multikey goes into an infinite loop </p> Ticket