Opened 10 years ago
Closed 10 years ago
#7796 closed Bugs (duplicate)
Memory leak in condition_variable
| Reported by: | Owned by: | viboes | |
|---|---|---|---|
| Milestone: | Component: | thread | |
| Version: | Boost 1.52.0 | Severity: | Regression |
| Keywords: | Cc: |
Description
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
Change History (2)
comment:1 by , 10 years ago
| Component: | threads → thread |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:2 by , 10 years ago
| Milestone: | To Be Determined |
|---|---|
| Resolution: | → duplicate |
| Status: | assigned → closed |

Duplicate #7657 Serious performance and memory consumption hit if condition_variable methods condition notify_one or notify_all is used repeatedly