'interrupted' when exiting
Simon Marlow
marlowsd at gmail.com
Mon Mar 4 14:32:47 CET 2013
On 04/03/13 06:02, Akio Takano wrote:
> Hi,
>
> If I compile and run the attached program in the following way, it
> crashes on exit:
>
> $ ghc -threaded thr_interrupted.hs
> $ ./thr_interrupted
> thr_interrupted: Main_dtl: interrupted
>
> This is particularly bad when profiling, because the program
> terminates before writing to the .prof file.
>
> Is this a bug in GHC, or am I supposed to terminate the thread before
> exiting? If it's a GHC issue, how should it be fixed? It seems that
> the error was raised in the C stub code GHC generated for the foreign
> import "wrapper" function.
So this behaviour is "by design", that is, I intended it to work this
way. That's not to say it's necessarily the best design; maybe a better
alternative exists.
The issue is this: when the main thread exits, the RTS starts shutting
down, and it kills all the other threads. If any of these threads were
the result of an external in-call from C, then that call returns, with
the status "Interrupted". Now, if this was a foreign export or a
foreign import "wrapper", then there is no provision for returning an
error code to the caller, so the foreign export must either
a) kill the current OS thread
b) kill the whole process
c) sleep indefinitely
Right now we do (b) I think. Perhaps (a) would be better; at least that
might fix your problem.
Cheers,
Simon
More information about the Glasgow-haskell-users
mailing list