diff --git a/driver-opencl.c b/driver-opencl.c index ac8d01c8..a3d02f47 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -1061,9 +1061,9 @@ select_cgpu: thr->rolling = thr->cgpu->rolling = 0; /* Reports the last time we tried to revive a sick GPU */ cgtime(&thr->sick); - if (!pthread_cancel(thr->pth)) { + if (!pthread_kill(thr->pth, 0)) { applog(LOG_WARNING, "Thread %d still exists, killing it off", thr_id); - pthread_join(thr->pth, NULL); + cg_completion_timeout(&thr_info_cancel_join, thr, 5000); thr->cgpu->drv->thread_shutdown(thr); } else applog(LOG_WARNING, "Thread %d no longer exists", thr_id); diff --git a/sgminer.c b/sgminer.c index 15008c37..052cfa11 100644 --- a/sgminer.c +++ b/sgminer.c @@ -3310,7 +3310,7 @@ static void disable_curses(void) static void kill_timeout(struct thr_info *thr) { - cg_completion_timeout(&thr_info_cancel, thr, 1000); + cg_completion_timeout(&thr_info_cancel_join, thr, 1000); } static void kill_mining(void) @@ -3322,21 +3322,9 @@ static void kill_mining(void) /* Kill the mining threads*/ rd_lock(&mining_thr_lock); for (i = 0; i < mining_threads; i++) { - pthread_t *pth = (pthread_t *) calloc(1, sizeof(pthread_t)); - thr = mining_thr[i]; - if (thr && PTH(thr) != 0L) - *pth = thr->pth; - thr_info_cancel(thr); forcelog(LOG_DEBUG, "Waiting for thread %d to finish...", thr->id); -#ifndef WIN32 - if (pth && *pth) - pthread_join(*pth, NULL); -#else - if (pth && pth->p) - pthread_join(*pth, NULL); -#endif - free(pth); + thr_info_cancel_join(thr); } rd_unlock(&mining_thr_lock); } diff --git a/util.c b/util.c index 846a56c0..67f96c10 100644 --- a/util.c +++ b/util.c @@ -825,13 +825,14 @@ int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) ( return pthread_create(&thr->pth, attr, start, arg); } -void thr_info_cancel(struct thr_info *thr) +void thr_info_cancel_join(struct thr_info *thr) { if (!thr) return; if (PTH(thr) != 0L) { pthread_cancel(thr->pth); + pthread_join(thr->pth, NULL); PTH(thr) = 0L; } cgsem_destroy(&thr->sem); diff --git a/util.h b/util.h index 1682f710..70b594c1 100644 --- a/util.h +++ b/util.h @@ -107,7 +107,7 @@ struct pool; enum dev_reason; struct cgpu_info; int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg); -void thr_info_cancel(struct thr_info *thr); +void thr_info_cancel_join(struct thr_info *thr); void cgtime(struct timeval *tv); void subtime(struct timeval *a, struct timeval *b); void addtime(struct timeval *a, struct timeval *b);