[Haskell-cafe] Why do "unsafe" foreign calls block other threads?
qdunkan at gmail.com
Tue Aug 3 18:22:34 EDT 2010
On Tue, Aug 3, 2010 at 3:06 PM, Gregory Crosswhite
<gcross at phys.washington.edu> wrote:
> But you've got it backwards: if the function I am calling can call back
> into Haskell (i.e., is marked as "safe"), then GHC *doesn't* block the
> world, but if the function I am calling will never call back into Haskell
> (i.e., is marked as "unsafe"), then GHC *does* block the world. The
> reasoning behind this choice of behaviors is exactly what I do not
"unsafe" calls are fast but unsafe. If they call back to haskell, or
take a long time, bad things will happen.
"safe" calls are safer: They can call back to haskell, block on IO, or
just wander off and do something CPU intensive. As is often the case,
you pay a little bit of efficiency for the safety, since the RTS has
to line up a few ducks to allow callbacks (and presumably
Just think of "unsafe" in relation to "unsafeIndex" or something.
It's faster, but you have to be sure the index is in bounds.
More information about the Haskell-Cafe