summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-07-21 11:18:14 +0200
committerZubin Duggal <zubin.duggal@gmail.com>2021-09-21 22:28:28 +0530
commit48cdaaefc3247b90eaf8d9dbecf1aef1cc2ababf (patch)
treecf82a61403eb46c2322ec1dd9535f85927958c65
parentb6345f562d70ed7045ebd4e736aec23461dc238e (diff)
downloadhaskell-48cdaaefc3247b90eaf8d9dbecf1aef1cc2ababf.tar.gz
RTS: try to fix timer races
* Pthread based timer was initialized started while some other parts of the RTS assume it is initialized stopped, e.g. in hs_init_ghc: /* Start the "ticker" and profiling timer but don't start until the * scheduler is up. However, the ticker itself needs to be initialized * before the scheduler to ensure that the ticker mutex is initialized as * moreCapabilities will attempt to acquire it. */ * after a fork, don't start the timer before the IOManager is initialized: the timer handler (handle_tick) might call wakeUpRts to perform an idle GC, which calls wakeupIOManager/ioManagerWakeup Found while debugging #18033/#20132 but I couldn't confirm if it fixes them. (cherry picked from commit d99e76ad3600b4c5051da6923fb7454346ed0b7b)
-rw-r--r--rts/Schedule.c5
-rw-r--r--rts/posix/itimer/Pthread.c2
2 files changed, 5 insertions, 2 deletions
diff --git a/rts/Schedule.c b/rts/Schedule.c
index 5722181f59..ae6b30917c 100644
--- a/rts/Schedule.c
+++ b/rts/Schedule.c
@@ -2196,7 +2196,6 @@ forkProcess(HsStablePtr *entry
// On Unix, all timers are reset in the child, so we need to start
// the timer again.
initTimer();
- startTimer();
// TODO: need to trace various other things in the child
// like startup event, capabilities, process info etc
@@ -2206,6 +2205,10 @@ forkProcess(HsStablePtr *entry
ioManagerStartCap(&cap);
#endif
+ // start timer after the IOManager is initialized
+ // (the idle GC may wake up the IOManager)
+ startTimer();
+
// Install toplevel exception handlers, so interruption
// signal will be sent to the main thread.
// See #12903
diff --git a/rts/posix/itimer/Pthread.c b/rts/posix/itimer/Pthread.c
index 7b968f28f0..71a8622181 100644
--- a/rts/posix/itimer/Pthread.c
+++ b/rts/posix/itimer/Pthread.c
@@ -169,7 +169,7 @@ void
initTicker (Time interval, TickProc handle_tick)
{
itimer_interval = interval;
- stopped = false;
+ stopped = true;
exited = false;
#if defined(HAVE_SIGNAL_H)
sigset_t mask, omask;