From 7dd8b316ace41c1bc5bd713545e7d57bcf62694e Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 16 Nov 2013 13:20:52 +1100 Subject: [PATCH] Prevent a deadlock with use of restart_threads by spawning a thread to send the driver flush work messages. Conflicts: cgminer.c --- cgminer.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cgminer.c b/cgminer.c index 0f5aa179..d0077190 100644 --- a/cgminer.c +++ b/cgminer.c @@ -3671,12 +3671,14 @@ int restart_wait(struct thr_info *thr, unsigned int mstime) static void flush_queue(struct cgpu_info *cgpu); -static void restart_threads(void) +static void *restart_thread(void __maybe_unused *arg) { struct pool *cp = current_pool(); struct cgpu_info *cgpu; int i, mt; + pthread_detach(pthread_self()); + /* Artificially set the lagging flag to avoid pool not providing work * fast enough messages after every long poll */ pool_tset(cp, &cp->lagging); @@ -3702,6 +3704,18 @@ static void restart_threads(void) mutex_lock(&restart_lock); pthread_cond_broadcast(&restart_cond); mutex_unlock(&restart_lock); + + return NULL; +} + +/* In order to prevent a deadlock via the various drv->flush_work + * implementations we send the restart messages via a separate thread. */ +static void restart_threads(void) +{ + pthread_t rthread; + + if (unlikely(pthread_create(&rthread, NULL, restart_thread, NULL))) + quit(1, "Failed to create restart thread"); } static void signal_work_update(void)