From 9efb073fd16c61f9770671add560aba72b109980 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 28 Jul 2014 23:57:10 +0200 Subject: [PATCH] Avoid crash on Client delete. --- libethereum/Client.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 904ed2040..c44b0bd52 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -100,6 +100,15 @@ void Client::ensureWorking() Client::~Client() { + if (m_work) + { + if (m_workState.load(std::memory_order_acquire) == Active) + m_workState.store(Deleting, std::memory_order_release); + while (m_workState.load(std::memory_order_acquire) != Deleted) + this_thread::sleep_for(chrono::milliseconds(10)); + m_work->join(); + m_work.reset(nullptr); + } stopNetwork(); }