Use control_lock to protect thr->pth for thread creation/destruction.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/miner.h b/miner.h
index 1a83158..6101006 100644
--- a/miner.h
+++ b/miner.h
@@ -453,6 +453,7 @@ extern int total_getworks, total_stale, total_discarded;
extern unsigned int local_work;
extern unsigned int total_go, total_ro;
extern int opt_log_interval;
+extern pthread_mutex_t control_lock;
#ifdef HAVE_OPENCL
typedef struct {
diff --git a/util.c b/util.c
index 0bf71dc..0b0bf80 100644
--- a/util.c
+++ b/util.c
@@ -669,7 +669,9 @@ int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (
{
int ret;
+ mutex_lock(&control_lock);
ret = pthread_create(&thr->pth, attr, start, arg);
+ mutex_unlock(&control_lock);
return ret;
}
@@ -680,11 +682,15 @@ void thr_info_cancel(struct thr_info *thr)
if (thr->q)
tq_freeze(thr->q);
+
+ /* control_lock protects thr->pth */
+ mutex_lock(&control_lock);
if (thr->pth) {
if (!pthread_cancel(thr->pth))
pthread_join(thr->pth, NULL);
thr->pth = 0L;
}
+ mutex_unlock(&control_lock);
}
bool get_dondata(char **url, char **userpass)