--eventlog-flush-interval leads can deadlock with RTS shutdown
This command reliably deadlocks on my computer:
```
ghc --numeric-version +RTS --eventlog-flush-interval=1 -l
```
If you inspect the backtraces..
```
Thread 2 (Thread 0x7fffe03fd6c0 (LWP 1974700) "ghc_ticker"):
#0 0x00007fffee69450e in __futex_abstimed_wait_common () from /nix/store/g8zyryr9cr6540xsyg4avqkwgxpnwj2a-glibc-2.40-66/lib/libc.so.6
#1 0x00007fffee696e68 in pthread_cond_wait@@GLIBC_2.3.2 () from /nix/store/g8zyryr9cr6540xsyg4avqkwgxpnwj2a-glibc-2.40-66/lib/libc.so.6
#2 0x00007ffff018b51d in waitCondition (pCond=0x7fffd8000b80, pMut=0x7fffd8000bb8) at rts/posix/OSThreads.c:143
#3 0x00007ffff00f5bef in waitForReturnCapability (task=0x7fffd8000b70) at rts/Capability.c:794
#4 0x00007ffff00f6048 in waitForCapability (pCap=0x7fffe03fcd50, task=0x7fffd8000b70) at rts/Capability.c:921
#5 0x00007ffff012f797 in acquireAllCapabilities (cap=0x0, task=0x7fffd8000b70) at rts/Schedule.c:1569
#6 0x00007ffff012f503 in stopAllCapabilitiesWith (pCap=0x0, task=0x7fffd8000b70, sync_type=SYNC_FLUSH_EVENT_LOG) at rts/Schedule.c:1455
#7 0x00007ffff01484b9 in flushEventLog (cap=0x0) at rts/eventlog/EventLog.c:1635
#8 0x00007ffff0141201 in handle_tick (unused=0) at rts/Timer.c:129
#9 0x00007ffff0189f9e in itimer_thread_func (_handle_tick=0x7ffff0141152 <handle_tick>) at rts/posix/ticker/TimerFd.c:154
#10 0x00007ffff018b74d in start_thread (param=0x5b6730) at rts/posix/OSThreads.c:218
#11 0x00007fffee6978ee in start_thread () from /nix/store/g8zyryr9cr6540xsyg4avqkwgxpnwj2a-glibc-2.40-66/lib/libc.so.6
#12 0x00007fffee71b9bc in __clone3 () from /nix/store/g8zyryr9cr6540xsyg4avqkwgxpnwj2a-glibc-2.40-66/lib/libc.so.6
Thread 1 (Thread 0x7ffff14ec180 (LWP 1974694) "ghc"):
#0 0x00007fffee69450e in __futex_abstimed_wait_common () from /nix/store/g8zyryr9cr6540xsyg4avqkwgxpnwj2a-glibc-2.40-66/lib/libc.so.6
#1 0x00007fffee6995b3 in __pthread_clockjoin_ex () from /nix/store/g8zyryr9cr6540xsyg4avqkwgxpnwj2a-glibc-2.40-66/lib/libc.so.6
#2 0x00007ffff018a47e in exitTicker (wait=true) at rts/posix/ticker/TimerFd.c:271
#3 0x00007ffff01413ee in exitTimer (wait=true) at rts/Timer.c:223
#4 0x00007ffff01277b3 in hs_exit_ (wait_foreign=false) at rts/RtsStartup.c:522
#5 0x00007ffff012796d in shutdownHaskellAndExit (n=0, fastExit=0) at rts/RtsStartup.c:686
#6 0x00007ffff0126675 in hs_main (argc=2, argv=0x7fffffff63a8, main_closure=0x581988, rts_config=...) at rts/RtsMain.c:104
#7 0x000000000057592a in main ()
(gdb)
```
You can see that the `ghc_ticker` thread is attempting to flush, and to flush it's waiting to take all capabilities.
The main thread is shutting down, and waiting for the ticker thread to finish.
Therefore we are deadlocked.
I will try a solution that if we are shutting down, we don't attempt to flush in the ticker thread.
issue