diff options
author | psychocrypt <psychocryptHPC@gmail.com> | 2018-05-01 20:46:02 +0200 |
---|---|---|
committer | Timothy Pearson <tpearson@raptorengineering.com> | 2018-06-04 21:07:11 +0000 |
commit | d68036dfe013c4949fdc636a5f60e599555fe2ca (patch) | |
tree | c9c3095f9a4e24fc54fba64392a109dc6141162a /xmrstak/backend/nvidia/minethd.cpp | |
parent | e13b0d27b1e3e31bf79342153bcc705d326b20b1 (diff) | |
download | xmr-stak-d68036dfe013c4949fdc636a5f60e599555fe2ca.zip xmr-stak-d68036dfe013c4949fdc636a5f60e599555fe2ca.tar.gz |
fix job consume (possible deadlock)
fix #1505
- fix possible deadlock of the executor thread
- fix racecondition during the job consumation
- remove switch_work in all classes `minethd`
- move `consume_work` into `globalStates`
Diffstat (limited to 'xmrstak/backend/nvidia/minethd.cpp')
-rw-r--r-- | xmrstak/backend/nvidia/minethd.cpp | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/xmrstak/backend/nvidia/minethd.cpp b/xmrstak/backend/nvidia/minethd.cpp index d14fbd4..05ee0c6 100644 --- a/xmrstak/backend/nvidia/minethd.cpp +++ b/xmrstak/backend/nvidia/minethd.cpp @@ -195,27 +195,6 @@ std::vector<iBackend*>* minethd::thread_starter(uint32_t threadOffset, miner_wor return pvThreads; } -void minethd::switch_work(miner_work& pWork) -{ - // iConsumeCnt is a basic lock-like polling mechanism just in case we happen to push work - // faster than threads can consume them. This should never happen in real life. - // Pool cant physically send jobs faster than every 250ms or so due to net latency. - - while (globalStates::inst().iConsumeCnt.load(std::memory_order_seq_cst) < globalStates::inst().iThreadCount) - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - - globalStates::inst().oGlobalWork = pWork; - globalStates::inst().iConsumeCnt.store(0, std::memory_order_seq_cst); - globalStates::inst().iGlobalJobNo++; -} - -void minethd::consume_work() -{ - memcpy(&oWork, &globalStates::inst().oGlobalWork, sizeof(miner_work)); - iJobNo++; - globalStates::inst().iConsumeCnt++; -} - void minethd::work_main() { if(affinity >= 0) //-1 means no affinity @@ -244,8 +223,6 @@ void minethd::work_main() uint32_t iNonce; - globalStates::inst().iConsumeCnt++; - uint8_t version = 0; size_t lastPoolId = 0; @@ -261,7 +238,7 @@ void minethd::work_main() while (globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) std::this_thread::sleep_for(std::chrono::milliseconds(100)); - consume_work(); + globalStates::inst().consume_work(oWork, iJobNo); continue; } uint8_t new_version = oWork.getVersion(); @@ -299,6 +276,9 @@ void minethd::work_main() { globalStates::inst().calc_start_nonce(iNonce, oWork.bNiceHash, h_per_round * 16); } + // check if the job is still valid, there is a small posibility that the job is switched + if(globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) != iJobNo) + break; uint32_t foundNonce[10]; uint32_t foundCount; @@ -337,7 +317,7 @@ void minethd::work_main() std::this_thread::yield(); } - consume_work(); + globalStates::inst().consume_work(oWork, iJobNo); } } |