Commit bb7b45dc authored by Simon Marlow's avatar Simon Marlow
Browse files

Don't Terminate the ticker thread (#3748)

parent cb7e8821
......@@ -370,7 +370,7 @@ hs_exit_(rtsBool wait_foreign)
/* stop the ticker */
stopTimer();
exitTimer();
exitTimer(wait_foreign);
// set the terminal settings back to what they were
#if !defined(mingw32_HOST_OS)
......
......@@ -16,7 +16,7 @@ typedef void (*TickProc)(int);
void initTicker (nat ms, TickProc handle_tick);
void startTicker (void);
void stopTicker (void);
void exitTicker (void);
void exitTicker (rtsBool wait);
END_RTS_PRIVATE
......
......@@ -114,9 +114,9 @@ stopTimer(void)
}
void
exitTimer(void)
exitTimer (rtsBool wait)
{
if (RtsFlags.MiscFlags.tickInterval != 0) {
exitTicker();
exitTicker(wait);
}
}
......@@ -10,6 +10,6 @@
#define TIMER_H
RTS_PRIVATE void initTimer (void);
RTS_PRIVATE void exitTimer (void);
RTS_PRIVATE void exitTimer (rtsBool wait);
#endif /* TIMER_H */
......@@ -221,7 +221,7 @@ stopTicker(void)
}
void
exitTicker(void)
exitTicker (rtsBool wait STG_UNUSED)
{
#if defined(USE_TIMER_CREATE)
timer_delete(timer);
......
......@@ -127,7 +127,7 @@ stopTicker(void)
}
void
exitTicker(void)
exitTicker (rtsBool wait)
{
// We must wait for the ticker thread to terminate, since if we
// are in a DLL that is about to be unloaded, the ticker thread
......@@ -138,10 +138,20 @@ exitTicker(void)
DWORD exitCode;
ticker_state = TickerExit;
SetEvent(hStopEvent);
while (1) {
WaitForSingleObject(tickThread, 20);
while (wait) {
// See #3748:
//
// when the RTS is compiled into a DLL (wait==rtsTrue),
// the ticker thread must stop before we exit, or chaos
// will ensue. We can't kill it, because it may be
// holding a lock.
//
// When not compiled into a DLL, we wait for
// the thread out of courtesy, but give up after 200ms if
// it still hasn't stopped.
WaitForSingleObject(tickThread, 200);
if (!GetExitCodeThread(tickThread, &exitCode)) {
return 1;
return;
}
if (exitCode != STILL_ACTIVE) {
tickThread = INVALID_HANDLE_VALUE;
......@@ -149,9 +159,8 @@ exitTicker(void)
CloseHandle(hStopEvent);
hStopEvent = INVALID_HANDLE_VALUE;
}
return 0;
return;
}
TerminateThread(tickThread, 0);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment