From bd2176ad9801e700faa97d6d102d81eab113c554 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 13 Dec 2010 00:06:36 +0100 Subject: [PATCH] TD_GAMES: Fix new deadlock when stop-signal and finish-signal would get coalesced --- uct/search.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/uct/search.c b/uct/search.c index 7402364..4c604e5 100644 --- a/uct/search.c +++ b/uct/search.c @@ -141,8 +141,14 @@ spawn_thread_manager(void *ctx_) /* Wait for some thread to finish... */ pthread_cond_wait(&finish_cond, &finish_mutex); if (finish_thread < 0) { - /* Stop-by-caller. Tell the workers to wrap up. */ + /* Stop-by-caller. Tell the workers to wrap up + * and unblock them from terminating. */ uct_halt = 1; + /* We need to make sure the workers do not complete + * the termination sequence before we get officially + * stopped - their wake and the stop wake could get + * coalesced. */ + pthread_mutex_unlock(&finish_serializer); continue; } /* ...and gather its remnants. */ @@ -196,6 +202,7 @@ uct_search_start(struct uct *u, struct board *b, enum stone color, static struct uct_thread_ctx mctx; mctx = (struct uct_thread_ctx) { .u = u, .b = b, .color = color, .t = t, .seed = fast_random(65536), .ti = ti }; s->ctx = &mctx; + pthread_mutex_lock(&finish_serializer); pthread_mutex_lock(&finish_mutex); pthread_create(&thread_manager, NULL, spawn_thread_manager, s->ctx); thread_manager_running = true; -- 2.11.4.GIT