[Haskell-cafe] Control.Concurrent export/import weirdness

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Mon Apr 13 07:32:20 EDT 2009


Jason Dusek wrote:
>   Why is this function exported then imported?

It causes the RTS to create a bound thread to run code in:
(reordering the code slightly)

>     foreign import ccall "forkOS_entry" forkOS_entry_reimported
>         :: StablePtr (IO ()) -> IO ()

This is a safe call, so it suspends the currently running RTS thread,
and then calls the forkOS_entry foreign function.

>     foreign export ccall forkOS_entry
>         :: StablePtr (IO ()) -> IO ()

The generated stub creates a new, bound RTS thread, and then calls the
forkOS_entry Haskell function.

>     forkOS_entry :: StablePtr (IO ()) -> IO ()
>     forkOS_entry stableAction = do
>             action <- deRefStablePtr stableAction
>             action

And this, finally, runs an action in the new thread.

See also section 3.4 of the "Extending the Haskell FFI with Concurrency"
paper,

   http://research.microsoft.com/en-us/um/people/simonpj/Papers/conc-ffi/index.htm
   (http://tinyurl.com/cocex7)

HTH,

Bertram


More information about the Haskell-Cafe mailing list