atzeus / FRPNow

Other
89 stars 14 forks source link

"Trivial" program results in "thread blocked indefinitely in an MVar operation" #2

Closed ocharles closed 9 years ago

ocharles commented 9 years ago

The following:

module Main where

import Control.FRPNow

main :: IO ()
main = runNowMaster (return never)

When compiled (with ghc --make -threaded) results in

Test: thread blocked indefinitely in an MVar operation

when executed.

atzeus commented 9 years ago

This is due to nothing actually happening. GHC runtime will detect that and then throw this error. I'll see if I can prevent it.

atzeus commented 9 years ago

Fixed! This will print the following in the next release:

FRP System has become inactive because nothing else is going to happen.We could keep on waiting forever, but instead we will just exit the FRP system now...Bye!

Xandaros commented 9 years ago

I was interested in how you implemented this, but I can't actually find the commit. Where was this done?

atzeus commented 9 years ago

Whoops, forgot to push. The code is at work, I'll push it tomorrow. Essentially, I catch an Indefinitly blocked on MVar exception.

int-index commented 9 years ago

@atzeus What if I want to catch it myself? I think throwing an exception is a sensible behavior, it just needs to be documented.

atzeus commented 9 years ago

Hmm, you're right. I propose throwing a FRPNowInactive exception, and documenting it. Agreed?

int-index commented 9 years ago

@atzeus Agreed, if you're sure that you can't accidentally catch exceptions thrown due to user-defined MVars (as opposed to MVars used by FRPNow internally).

atzeus commented 9 years ago

Sadly, I can't guarantee that, since IndefinitlyBlockedOnMVar exception does not tell which MVar is involved :( I propose I document that as well..

int-index commented 9 years ago

Throwing FRPNowInactive when the thread is blocked on a user-defined MVar isn't better than throwing IndefinitelyBlockedOnMVar when the FRP system is inactive.

I think it's better not to mess with this and just document that when the FRP system becomes inactive, an MVar exception may be thrown.

atzeus commented 9 years ago

Agreed. I propose I just dump a message to standard error saying that the following exception may be due to the FRP system becoming inactive and (re)throw the indefinitly blocked on MVar exception. Agreed?

int-index commented 9 years ago

I don't like libraries doing IO without my consent or explicit command. Messages are something the user can see, but this message is targeted at the developer.

But that's just me.

atzeus commented 9 years ago

I just realized that it is actually possible to guarantee that a FRPSystemInactive exception comes from the FRPNow MVar instead of a user defined MVar, so I will just do that :)

int-index commented 9 years ago

Perfect! :)

atzeus commented 9 years ago

Commited!