Fix short_read test race/deadlock

This commit is contained in:
Vinnie Falco
2016-02-09 15:14:43 -05:00
parent 8c11d24454
commit 9f5b58c8ab

View File

@@ -140,13 +140,25 @@ private:
void
close()
{
std::unique_lock<std::mutex> lock(mutex_);
if (closed_)
return;
closed_ = true;
for(auto& c : list_)
if(auto p = c.second.lock())
p->close();
std::vector<std::shared_ptr<Child>> v;
{
std::unique_lock<std::mutex> lock(mutex_);
v.reserve(list_.size());
if (closed_)
return;
closed_ = true;
for(auto const& c : list_)
{
if(auto p = c.second.lock())
{
p->close();
// Must destroy shared_ptr outside the
// lock otherwise deadlock from the
// managed object's destructor.
v.emplace_back(std::move(p));
}
}
}
}
void