summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpsychocrypt <psychocrypt@users.noreply.github.com>2017-07-27 21:28:40 +0200
committerGitHub <noreply@github.com>2017-07-27 21:28:40 +0200
commitb64d5851aa857e035c573f4c6ecd7d9ab3cc3d48 (patch)
tree1ccfaaf59cbfe76846a40ce456b6ba8ef942d25a
parent238a513af7410fa3ddcc86b2adb2d53e2c29b9d1 (diff)
parentc2203be45654c048d5571cc019314bc702e353ff (diff)
downloadxmr-stak-b64d5851aa857e035c573f4c6ecd7d9ab3cc3d48.zip
xmr-stak-b64d5851aa857e035c573f4c6ecd7d9ab3cc3d48.tar.gz
Merge pull request #254 from fireice-uk/topic-race-fix
Race condition fix
-rw-r--r--minethd.cpp4
-rw-r--r--minethd.h3
2 files changed, 7 insertions, 0 deletions
diff --git a/minethd.cpp b/minethd.cpp
index 5c7871d..fac9fb4 100644
--- a/minethd.cpp
+++ b/minethd.cpp
@@ -161,6 +161,7 @@ minethd::minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefet
bNoPrefetch = no_prefetch;
this->affinity = affinity;
+ std::lock_guard<std::mutex> lock(work_thd_mtx);
if(double_work)
oWorkThd = std::thread(&minethd::double_work_main, this);
else
@@ -363,6 +364,9 @@ minethd::cn_hash_fun minethd::func_selector(bool bHaveAes, bool bNoPrefetch)
void minethd::pin_thd_affinity()
{
+ //Lock is needed because we need to use oWorkThd
+ std::lock_guard<std::mutex> lock(work_thd_mtx);
+
// pin memory to NUMA node
bindMemoryToNUMANode(affinity);
diff --git a/minethd.h b/minethd.h
index 3c88c26..293e8de 100644
--- a/minethd.h
+++ b/minethd.h
@@ -1,6 +1,7 @@
#pragma once
#include <thread>
#include <atomic>
+#include <mutex>
#include "crypto/cryptonight.h"
class telemetry
@@ -130,6 +131,8 @@ private:
miner_work oWork;
void pin_thd_affinity();
+ // Held by the creating context to prevent a race cond with oWorkThd = std::thread(...)
+ std::mutex work_thd_mtx;
std::thread oWorkThd;
uint8_t iThreadNo;
OpenPOWER on IntegriCloud