Skip to content

Commit 0bd7a9f

Browse files
committed
After cancelling a thread (unless it's detached, but mining threads aren't), it is always necessary to join the thread so the system will release resources.
This also simplifies kill_mining a bit.
1 parent e33590f commit 0bd7a9f

File tree

4 files changed

+7
-18
lines changed

4 files changed

+7
-18
lines changed

driver-opencl.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1061,9 +1061,9 @@ void *reinit_gpu(void *userdata)
10611061
thr->rolling = thr->cgpu->rolling = 0;
10621062
/* Reports the last time we tried to revive a sick GPU */
10631063
cgtime(&thr->sick);
1064-
if (!pthread_cancel(thr->pth)) {
1064+
if (!pthread_kill(thr->pth, 0)) {
10651065
applog(LOG_WARNING, "Thread %d still exists, killing it off", thr_id);
1066-
pthread_join(thr->pth, NULL);
1066+
cg_completion_timeout(&thr_info_cancel_join, thr, 5000);
10671067
thr->cgpu->drv->thread_shutdown(thr);
10681068
} else
10691069
applog(LOG_WARNING, "Thread %d no longer exists", thr_id);

sgminer.c

+2-14
Original file line numberDiff line numberDiff line change
@@ -3310,7 +3310,7 @@ static void disable_curses(void)
33103310

33113311
static void kill_timeout(struct thr_info *thr)
33123312
{
3313-
cg_completion_timeout(&thr_info_cancel, thr, 1000);
3313+
cg_completion_timeout(&thr_info_cancel_join, thr, 1000);
33143314
}
33153315

33163316
static void kill_mining(void)
@@ -3322,21 +3322,9 @@ static void kill_mining(void)
33223322
/* Kill the mining threads*/
33233323
rd_lock(&mining_thr_lock);
33243324
for (i = 0; i < mining_threads; i++) {
3325-
pthread_t *pth = (pthread_t *) calloc(1, sizeof(pthread_t));
3326-
33273325
thr = mining_thr[i];
3328-
if (thr && PTH(thr) != 0L)
3329-
*pth = thr->pth;
3330-
thr_info_cancel(thr);
33313326
forcelog(LOG_DEBUG, "Waiting for thread %d to finish...", thr->id);
3332-
#ifndef WIN32
3333-
if (pth && *pth)
3334-
pthread_join(*pth, NULL);
3335-
#else
3336-
if (pth && pth->p)
3337-
pthread_join(*pth, NULL);
3338-
#endif
3339-
free(pth);
3327+
thr_info_cancel_join(thr);
33403328
}
33413329
rd_unlock(&mining_thr_lock);
33423330
}

util.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -825,13 +825,14 @@ int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (
825825
return pthread_create(&thr->pth, attr, start, arg);
826826
}
827827

828-
void thr_info_cancel(struct thr_info *thr)
828+
void thr_info_cancel_join(struct thr_info *thr)
829829
{
830830
if (!thr)
831831
return;
832832

833833
if (PTH(thr) != 0L) {
834834
pthread_cancel(thr->pth);
835+
pthread_join(thr->pth, NULL);
835836
PTH(thr) = 0L;
836837
}
837838
cgsem_destroy(&thr->sem);

util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ struct pool;
107107
enum dev_reason;
108108
struct cgpu_info;
109109
int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
110-
void thr_info_cancel(struct thr_info *thr);
110+
void thr_info_cancel_join(struct thr_info *thr);
111111
void cgtime(struct timeval *tv);
112112
void subtime(struct timeval *a, struct timeval *b);
113113
void addtime(struct timeval *a, struct timeval *b);

0 commit comments

Comments
 (0)