Skip to content
Snippets Groups Projects
Unverified Commit 37ad8856 authored by Sylvain Henry's avatar Sylvain Henry Committed by Zubin
Browse files

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 5f3991c7)
parent 001483ed
No related branches found
No related tags found
No related merge requests found
...@@ -2157,7 +2157,6 @@ forkProcess(HsStablePtr *entry ...@@ -2157,7 +2157,6 @@ forkProcess(HsStablePtr *entry
// On Unix, all timers are reset in the child, so we need to start // On Unix, all timers are reset in the child, so we need to start
// the timer again. // the timer again.
initTimer(); initTimer();
startTimer();
// TODO: need to trace various other things in the child // TODO: need to trace various other things in the child
// like startup event, capabilities, process info etc // like startup event, capabilities, process info etc
...@@ -2167,6 +2166,10 @@ forkProcess(HsStablePtr *entry ...@@ -2167,6 +2166,10 @@ forkProcess(HsStablePtr *entry
ioManagerStartCap(&cap); ioManagerStartCap(&cap);
#endif #endif
// start timer after the IOManager is initialized
// (the idle GC may wake up the IOManager)
startTimer();
// Install toplevel exception handlers, so interruption // Install toplevel exception handlers, so interruption
// signal will be sent to the main thread. // signal will be sent to the main thread.
// See #12903 // See #12903
......
...@@ -168,7 +168,7 @@ void ...@@ -168,7 +168,7 @@ void
initTicker (Time interval, TickProc handle_tick) initTicker (Time interval, TickProc handle_tick)
{ {
itimer_interval = interval; itimer_interval = interval;
stopped = false; stopped = true;
exited = false; exited = false;
#if defined(HAVE_SIGNAL_H) #if defined(HAVE_SIGNAL_H)
sigset_t mask, omask; sigset_t mask, omask;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment