[commit: ghc] wip/T16150: itimer: Don't free condvar until we know ticker is stopped (65c2b24)

git at git.haskell.org git at git.haskell.org
Wed Jan 9 21:36:22 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/T16150
Link       : http://ghc.haskell.org/trac/ghc/changeset/65c2b249a398bcd1c53acf51f36c2018d5b78ef3/ghc

>---------------------------------------------------------------

commit 65c2b249a398bcd1c53acf51f36c2018d5b78ef3
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Wed Jan 9 00:20:19 2019 -0500

    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.


>---------------------------------------------------------------

65c2b249a398bcd1c53acf51f36c2018d5b78ef3
 rts/posix/itimer/Pthread.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rts/posix/itimer/Pthread.c b/rts/posix/itimer/Pthread.c
index d8f2497..817c40f 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);
     }



More information about the ghc-commits mailing list