Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deadlock in tests (Continued) #2050

Merged
merged 1 commit into from Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions nano/node/bootstrap.cpp
Expand Up @@ -1646,7 +1646,6 @@ thread ([this]() {
nano::bootstrap_initiator::~bootstrap_initiator ()
{
stop ();
thread.join ();
}

void nano::bootstrap_initiator::bootstrap ()
Expand Down Expand Up @@ -1769,15 +1768,22 @@ std::shared_ptr<nano::bootstrap_attempt> nano::bootstrap_initiator::current_atte

void nano::bootstrap_initiator::stop ()
{
if (!stopped.exchange (true))
{
std::unique_lock<std::mutex> lock (mutex);
stopped = true;
if (attempt != nullptr)
{
attempt->stop ();
std::lock_guard<std::mutex> guard (mutex);
if (attempt != nullptr)
{
attempt->stop ();
}
}
condition.notify_all ();

if (thread.joinable ())
{
thread.join ();
}
}
condition.notify_all ();
}

void nano::bootstrap_initiator::notify_listeners (bool in_progress_a)
Expand Down
2 changes: 1 addition & 1 deletion nano/node/bootstrap.hpp
Expand Up @@ -251,7 +251,7 @@ class bootstrap_initiator final
private:
nano::node & node;
std::shared_ptr<nano::bootstrap_attempt> attempt;
bool stopped;
std::atomic<bool> stopped;
std::mutex mutex;
std::condition_variable condition;
std::mutex observers_mutex;
Expand Down