Akio Takano | 4 Mar 07:02 2013
Picon

'interrupted' when exiting

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.

Regards,
Takano Akio
Attachment (thr_interrupted.hs): application/octet-stream, 518 bytes
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Simon Marlow | 4 Mar 14:32 2013
Picon

Re: 'interrupted' when exiting

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
(Continue reading)


Gmane