From 879f443ce1a08c41a8fd3d76a97139d8eeff2a57 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 25 Jun 2015 16:23:44 +0200 Subject: [PATCH] Avoid rzce condition. --- libethcore/EthashAux.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libethcore/EthashAux.cpp b/libethcore/EthashAux.cpp index 14a44a812..efb6066f7 100644 --- a/libethcore/EthashAux.cpp +++ b/libethcore/EthashAux.cpp @@ -119,9 +119,11 @@ void EthashAux::killCache(h256 const& _s) EthashAux::LightType EthashAux::light(h256 const& _seedHash) { - ReadGuard l(get()->x_lights); - LightType ret = get()->m_lights[_seedHash]; - return ret ? ret : (get()->m_lights[_seedHash] = make_shared(_seedHash)); + UpgradableGuard l(get()->x_lights); + if (get()->m_lights.count(_seedHash)) + return get()->m_lights.at(_seedHash); + UpgradeGuard l2(l); + return (get()->m_lights[_seedHash] = make_shared(_seedHash)); } EthashAux::LightAllocation::LightAllocation(h256 const& _seedHash)