[commit: ghc] wip/ghc-8.6-merge: itimer: Don't free condvar until we know ticker is stopped (7ec385f)

git at git.haskell.org git at git.haskell.org
Sat Feb 9 18:22:39 UTC 2019


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

On branch  : wip/ghc-8.6-merge
Link       : http://ghc.haskell.org/trac/ghc/changeset/7ec385f40406a23da7a52fd5a07131efb8973233/ghc

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

commit 7ec385f40406a23da7a52fd5a07131efb8973233
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.
    
    (cherry picked from commit 7b12b3f0240321ac1ee43f14eb9c07e015022eeb)


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

7ec385f40406a23da7a52fd5a07131efb8973233
 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 f591d5e..90923c6 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