diff --git a/sgminer.c b/sgminer.c index cf9db437..1c4d3313 100644 --- a/sgminer.c +++ b/sgminer.c @@ -7744,7 +7744,8 @@ static void restart_mining_threads(unsigned int new_n_threads) } } - rd_lock(&mining_thr_lock); + wr_lock(&mining_thr_lock); + if (mining_thr) { for (i = 0; i < total_devices; ++i) { free(devices[i]->thr); @@ -7785,10 +7786,13 @@ static void restart_mining_threads(unsigned int new_n_threads) cgtime(&thr->last); cgpu->thr[j] = thr; + + if (!cgpu->drv->thread_prepare(thr)) + continue; } } - rd_unlock(&mining_thr_lock); + wr_unlock(&mining_thr_lock); for (i = 0; i < total_devices; ++i) { struct cgpu_info *cgpu = devices[i]; @@ -7796,9 +7800,6 @@ static void restart_mining_threads(unsigned int new_n_threads) for (j = 0; j < cgpu->threads; ++j) { thr = cgpu->thr[j]; - if (!cgpu->drv->thread_prepare(thr)) - continue; - if (unlikely(thr_info_create(thr, NULL, miner_thread, thr))) quit(1, "thread %d create failed", thr->id);