[commit: ghc] wip/T16185: itimer: Don't free condvar until we know ticker is stopped (7b12b3f)

git at git.haskell.org git at git.haskell.org
Tue Jan 15 17:43:40 UTC 2019


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

On branch  : wip/T16185
Link       : http://ghc.haskell.org/trac/ghc/changeset/7b12b3f0240321ac1ee43f14eb9c07e015022eeb/ghc

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

commit 7b12b3f0240321ac1ee43f14eb9c07e015022eeb
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.


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

7b12b3f0240321ac1ee43f14eb9c07e015022eeb
 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