Commit 5b9cf0f0779a9838e6ec1edc4ac5ff8d72007e51

ckolivas 2013-05-29T12:06:06

Send the shutdown message to threads and do the thread shutdown functions before more forcefully sending pthread_cancel to threads.

diff --git a/cgminer.c b/cgminer.c
index 85066f7..6950b61 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2809,17 +2809,29 @@ static void __kill_work(void)
 	thr = &control_thr[watchdog_thr_id];
 	thr_info_cancel(thr);
 
-	applog(LOG_DEBUG, "Killing off mining threads");
-	/* Kill the mining threads*/
+	applog(LOG_DEBUG, "Shutting down mining threads");
 	for (i = 0; i < mining_threads; i++) {
-		pthread_t *pth = NULL;
+		struct cgpu_info *cgpu;
+		struct device_drv *drv;
 
 		thr = get_thread(i);
-		if (thr) {
-			struct device_drv *drv = thr->cgpu->drv;
+		if (!thr)
+			continue;
+		cgpu = thr->cgpu;
+		if (!cgpu)
+			continue;
+		drv = cgpu->drv;
+		if (!drv)
+			continue;
 
-			drv->thread_shutdown(thr);
-		}
+		cgpu->shutdown = true;
+		drv->thread_shutdown(thr);
+	}
+
+	applog(LOG_DEBUG, "Killing off mining threads");
+	/* Kill the mining threads*/
+	for (i = 0; i < mining_threads; i++) {
+		pthread_t *pth = NULL;
 
 		if (thr && PTH(thr) != 0L)
 			pth = &thr->pth;