Boost C++ Libraries: Ticket #7796: Memory leak in condition_variable https://svn.boost.org/trac10/ticket/7796 <p> Hi, </p> <p> an internal structure within condition_variable keeps growing and so does CPU consumption, until it brings my application to a crawl. </p> <p> My analysis: </p> <p> The follwing change in the recent boost version is responsible: boost/thread/win32/condition_variable.hpp: </p> <p> Now: (boost 1.52) </p> <pre class="wiki"> ~entry_manager() { if (! entry-&gt;is_notified()) { entry-&gt;remove_waiter(); } } </pre><p> Before: (boost 1.51) </p> <pre class="wiki"> ~entry_manager() { entry-&gt;remove_waiter(); } </pre><p> Result: basic_condition_variable::generations keeps growing endlessly; source: </p> <pre class="wiki">class basic_condition_variable { entry_ptr get_wait_entry() { [...] entry_ptr new_entry(new list_entry(wake_sem)); [...] }; </pre><p> My test code: </p> <pre class="wiki">//producer: void setWorkload(const std::vector&lt;Zstring&gt;&amp; newLoad) //context of main thread { { boost::unique_lock&lt;boost::mutex&gt; dummy(lockFiles); filesToLoad = newLoad; } conditionNewFiles.notify_one(); } //consumer Zstring extractNextFile() //context of worker thread, blocking { boost::unique_lock&lt;boost::mutex&gt; dummy(lockFiles); while (filesToLoad.empty()) conditionNewFiles.timed_wait(dummy, boost::posix_time::milliseconds(50)); //interruption point! Zstring fileName = filesToLoad.back(); filesToLoad.pop_back(); return fileName; } </pre><p> Expectation: conditionNewFiles.timed_wait() should not increase "basic_condition_variable::generations"! </p> <p> Test to verify this bug: </p> <p> Using "conditionNewFiles.notify_all()" instead of "conditionNewFiles.notify_one()" let's my application behave correctly without growing CPU consumption; internal table "basic_condition_variable::generations" has one entry. </p> <p> Regards, Zenju </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7796 Trac 1.4.3 viboes Fri, 14 Dec 2012 13:10:49 GMT owner, status, component changed https://svn.boost.org/trac10/ticket/7796#comment:1 https://svn.boost.org/trac10/ticket/7796#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>component</strong> <span class="trac-field-old">threads</span> → <span class="trac-field-new">thread</span> </li> </ul> Ticket viboes Fri, 14 Dec 2012 13:12:44 GMT status changed; resolution set; milestone deleted https://svn.boost.org/trac10/ticket/7796#comment:2 https://svn.boost.org/trac10/ticket/7796#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">To Be Determined</span> </li> </ul> <p> Duplicate <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7657" title="#7657: Bugs: Serious performance and memory consumption hit if condition_variable ... (closed: fixed)">#7657</a> Serious performance and memory consumption hit if condition_variable methods condition notify_one or notify_all is used repeatedly </p> Ticket