[Haskell-cafe] turn off "thread blocked indefinitely in an STM transaction"?

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Tue Nov 17 08:52:27 UTC 2015

I find the following mildly annoying:

Prelude> import Control.Concurrent.STM
Prelude Control.Concurrent.STM> atomically retry
*** Exception: thread blocked indefinitely in an STM transaction

Is there a way to not raise this exception, and block the thread?

I don't see this behaviour (raising the exception)
mentioned in the API docs nor in the defining paper
(Composable memory transactions, PPoPP'05) that is referenced there.

I understand it might come in handy for debugging,
but sometimes (e.g., for teaching)
I might really want a transaction that never commits.

For instance, I am forkIO'ing some worker threads
and the main program really should do absolutely nothing.
So I thought I could just block the main thread.

I can make some work-around with

forM [1..n] $ \ p ->
      ( if p < n then void . forkIO else id ) $ forever $ do

but that feels clumsy (since asymmetric).

- J.W.

More information about the Haskell-Cafe mailing list