diff options
author | Lia Lenckowski <lialenck@protonmail.com> | 2023-08-28 12:08:53 +0200 |
---|---|---|
committer | Lia Lenckowski <lialenck@protonmail.com> | 2023-08-28 12:08:53 +0200 |
commit | 6ea0264d32d5337c033d3865e16f6f35dfbe47f0 (patch) | |
tree | cd6822d7f921e08de3f8a3414a4a1a6833c23525 | |
parent | 830b0a56e92bd6855c6ec18582911824e743ffc1 (diff) | |
download | fastbangs-6ea0264d32d5337c033d3865e16f6f35dfbe47f0.tar fastbangs-6ea0264d32d5337c033d3865e16f6f35dfbe47f0.tar.bz2 fastbangs-6ea0264d32d5337c033d3865e16f6f35dfbe47f0.tar.zst |
don't deadlock on multiple stops
-rw-r--r-- | src/BatchedRunner.hs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/BatchedRunner.hs b/src/BatchedRunner.hs index 83a704c..89dd3a8 100644 --- a/src/BatchedRunner.hs +++ b/src/BatchedRunner.hs @@ -31,7 +31,14 @@ makeRunner f n = do unless (fromMaybe False mayB) $ runnerLoop mv stopRunner :: Runner -> IO () -stopRunner (Runner mv) = atomically $ putTMVar mv True +stopRunner (Runner mv) = atomically $ do + mayB <- tryReadTMVar mv + case mayB of + -- if stopped/stopping, do nothing + Just True -> return () + -- if idle or working, block, such that the Runner has a chance to see that + -- it should fire before stopping + _ -> putTMVar mv True notifyRunner :: Runner -> IO () notifyRunner (Runner mv) = void $ atomically $ tryPutTMVar mv False |