C that setjmps -> haskell -> C that might longjmp

If I have the following call sequence C code -> Haskell code -> various C code bits where the various C code bits on the right might do a longjmp (their version of an exception) and jumping back to the C code on the left. Is it possible to have C code on the left then somehow tell GHC to cleanup the aborted Haskell code/resume executing it with an exception, or is the only option to setjmp wrap all the various C code bits on the right? Thanks! -Tyson

On 01/03/2010 17:06, Tyson Whitehead wrote:
If I have the following call sequence
C code -> Haskell code -> various C code bits
where the various C code bits on the right might do a longjmp (their version of an exception) and jumping back to the C code on the left.
eek.
Is it possible to have C code on the left then somehow tell GHC to cleanup the aborted Haskell code/resume executing it with an exception, or is the only option to setjmp wrap all the various C code bits on the right?
We don't have a way to do this, no. It would require some hacking in the RTS. The RTS has stashed away information about the call in progress and is expecting the call to return, so when you longjmp() the RTS will probably get very confused. For now I suggest you use setjmp. If you want to suggest an API to tell the RTS about a longjmp, then perhaps we could implement something, but I'm not sure what the API would look like, because you don't have a handle to the in-progress calls. In RTS-speak you need to tell the RTS about which Tasks have been terminated. I've actually been tinkering with this code a bit recently so there is now a structure called InCall which replaces some of what Task was for, but the idea is similar. Cheers, Simon

On March 2, 2010 06:17:46 Simon Marlow wrote:
For now I suggest you use setjmp. If you want to suggest an API to tell the RTS about a longjmp, then perhaps we could implement something, but I'm not sure what the API would look like, because you don't have a handle to the in-progress calls. In RTS-speak you need to tell the RTS about which Tasks have been terminated. I've actually been tinkering with this code a bit recently so there is now a structure called InCall which replaces some of what Task was for, but the idea is similar.
Thanks Simon, I haven't quite managed to wrap my head around how the os threads, haskell threads, tasks, and capabilities all fits together in the rts, so I don't have any ideas to suggest for a relevant API. I'll setjmp wrap them. I was guessing that was the most likely option. : ) Cheers! -Tyson
participants (2)
-
Simon Marlow
-
Tyson Whitehead