Browse Source

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.
djm34
Jan Berdajs 11 years ago
parent
commit
0bd7a9ff63
  1. 4
      driver-opencl.c
  2. 16
      sgminer.c
  3. 3
      util.c
  4. 2
      util.h

4
driver-opencl.c

@ -1061,9 +1061,9 @@ select_cgpu: @@ -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);

16
sgminer.c

@ -3310,7 +3310,7 @@ static void disable_curses(void) @@ -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) @@ -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);
}

3
util.c

@ -825,13 +825,14 @@ int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) ( @@ -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);

2
util.h

@ -107,7 +107,7 @@ struct pool; @@ -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);

Loading…
Cancel
Save