From 00d17d16fee1dc66719eec9b424f3682ddd168dd Mon Sep 17 00:00:00 2001 From: Jan Berdajs Date: Thu, 5 Jun 2014 22:55:11 +0200 Subject: [PATCH] fix segfault (watchdog thread declares threads sick and tries to restart them while they are already being restarted) --- sgminer.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sgminer.c b/sgminer.c index 020fbd36..4cab3636 100644 --- a/sgminer.c +++ b/sgminer.c @@ -7412,6 +7412,8 @@ static void *watchdog_thread(void __maybe_unused *userdata) hashmeter(-1, &zero_tv, 0); + rd_lock(&mining_thr_lock); + #ifdef HAVE_CURSES if (curses_active_locked()) { struct cgpu_info *cgpu; @@ -7547,6 +7549,7 @@ static void *watchdog_thread(void __maybe_unused *userdata) reinit_device(cgpu); } } + rd_unlock(&mining_thr_lock); } return NULL; @@ -8122,6 +8125,10 @@ static void restart_mining_threads(unsigned int new_n_threads) thr->cgpu->drv->thread_shutdown(thr); thr->cgpu->shutdown = false; } + } + + rd_lock(&mining_thr_lock); + if (mining_thr) { for (i = 0; i < total_devices; ++i) { free(devices[i]->thr); } @@ -8159,14 +8166,26 @@ static void restart_mining_threads(unsigned int new_n_threads) thr->cgpu = cgpu; thr->device_thread = j; + cgtime(&thr->last); + + cgpu->thr[j] = thr; + } + } + + rd_unlock(&mining_thr_lock); + + for (i = 0; i < total_devices; ++i) { + struct cgpu_info *cgpu = devices[i]; + + 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); - cgpu->thr[j] = thr; - /* Enable threads for devices set not to mine but disable * their queue in case we wish to enable them later */ if (cgpu->deven != DEV_DISABLED) {