Subject: [Boost-bugs] [Boost C++ Libraries] #7796: Memory leak in condition_variable
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-12-14 12:28:03
#7796: Memory leak in condition_variable
------------------------------+---------------------------------------------
Reporter: zhnmju123@⦠| Owner: anthonyw
Type: Bugs | Status: new
Milestone: To Be Determined | Component: threads
Version: Boost 1.52.0 | Severity: Regression
Keywords: |
------------------------------+---------------------------------------------
Hi,
an internal structure within condition_variable keeps growing and so does
CPU consumption, until it brings my application to a crawl.
My analysis:
The follwing change in the recent boost version is responsible:
boost/thread/win32/condition_variable.hpp:
Now: (boost 1.52)
{{{
~entry_manager()
{
if (! entry->is_notified())
{
entry->remove_waiter();
}
}
}}}
Before: (boost 1.51)
{{{
~entry_manager()
{
entry->remove_waiter();
}
}}}
Result:
basic_condition_variable::generations keeps growing endlessly; source:
{{{
class basic_condition_variable
{
entry_ptr get_wait_entry()
{
[...]
entry_ptr new_entry(new list_entry(wake_sem));
[...]
};
}}}
My test code:
{{{
//producer:
void setWorkload(const std::vector<Zstring>& newLoad) //context of
main thread
{
{
boost::unique_lock<boost::mutex> dummy(lockFiles);
filesToLoad = newLoad;
}
conditionNewFiles.notify_one();
}
//consumer
Zstring extractNextFile() //context of worker thread, blocking
{
boost::unique_lock<boost::mutex> 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;
}
}}}
Expectation:
conditionNewFiles.timed_wait() should not increase
"basic_condition_variable::generations"!
Test to verify this bug:
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.
Regards, Zenju
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7796> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC