summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-01-09 00:20:19 -0500
committerBen Gamari <ben@smart-cactus.org>2019-01-28 18:07:38 -0500
commit7ec385f40406a23da7a52fd5a07131efb8973233 (patch)
tree080b91d61cd2147c8ef8fe0ee135e557906ff1eb
parentff47e60a9d017e5d749ff5e29e61d6f1a558d142 (diff)
downloadhaskell-7ec385f40406a23da7a52fd5a07131efb8973233.tar.gz
itimer: Don't free condvar until we know ticker is stopped
When we are shutting down the pthread ticker we signal the start_cond condition variable to ensure that the ticker thread wakes up and exits in a reasonable amount of time. Previously, when the ticker thread would shut down it was responsible for freeing the start_cond condition variable. However, this would lead to a race wherein the ticker would free start_cond, then the main thread would try to signal it in an effort to wake the ticker (#16150). Avoid this by moving the mutex destruction to the main thread. (cherry picked from commit 7b12b3f0240321ac1ee43f14eb9c07e015022eeb)
-rw-r--r--rts/posix/itimer/Pthread.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/rts/posix/itimer/Pthread.c b/rts/posix/itimer/Pthread.c
index f591d5eb73..90923c69c8 100644
--- a/rts/posix/itimer/Pthread.c
+++ b/rts/posix/itimer/Pthread.c
@@ -147,8 +147,6 @@ static void *itimer_thread_func(void *_handle_tick)
if (USE_TIMERFD_FOR_ITIMER)
close(timerfd);
- closeMutex(&mutex);
- closeCondition(&start_cond);
return NULL;
}
@@ -207,6 +205,8 @@ exitTicker (bool wait)
if (pthread_join(thread, NULL)) {
sysErrorBelch("Itimer: Failed to join");
}
+ closeMutex(&mutex);
+ closeCondition(&start_cond);
} else {
pthread_detach(thread);
}