How to to terminate runStmt in "GHC as a library"

Simon Marlow simonmarhaskell at
Mon May 21 06:14:03 EDT 2007

Mads Lindstrøm wrote:
> Hi all
> I am trying to build a GUI for GHCi using "GHC as a library". See
> .
> One requirement is that the GUI is still responsive when executing code
> using GHC.runStmt. Therefore I do:
>    forkIO $ GHC.runStmt someStatement >> return()

Yikes!  I'm not at all sure that we support doing anything except using the GHC 
API from a single thread.  In fact I'm pretty sure we don't.  We should document 

There's nothing stopping you from having a separate GHC API thread that 
communicates with the other threads in your program (this is what Visual Haskell 
does, incedentally), so I'm pretty sure you can still do what you want.

> While this works fine, it does give me one problem. How do I terminate a
> call to runStmt prematurely? One would think that this would work:
>    threadId <-forkIO $ GHC.runStmt someStatement >> return()
>    ...
>    killThread threadId
> However, as runStmt also uses forkIO internally I am not killing the
> thread that runs "someStatement" - actually nothing seems to happen when
> executing the action "killThread threadId".
> Anybody knows how to kill the thread running "someStatement"?

The only way at the moment would be to look at Panic.interruptTargetThread, 
which contains a list of ThreadIds that we send ^C exceptions to (I don't think 
it really needs to be a list, you could probably just take the head).

Also, please submit a feature request so we can figure out an extension to the 
API to support interrupting runStmts.


More information about the Glasgow-haskell-users mailing list