[Haskell-cafe] safe vs unsafe

Adam Langley agl at imperialviolet.org
Tue Jun 24 13:03:04 EDT 2008


2008/6/23 Galchin, Vasili <vigalchin at gmail.com>:
> aio: schedule: re-entered unsafely.
>    Perhaps a 'foreign import unsafe' should be 'safe'?
>
> I want to understand from an implementation viewpoint .. deeper. This is a
> GC issue yes?

Are you reentering Haskell on a path which involves an unsafe FFI
call? e.g. you enter C land via an unsafe FFI call and, on the same
call path, reenter Haskell with a callback?

http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi/ffise3.html#x6-130003.3 says:

"Optionally, an import declaration can specify, after the calling
convention, the safety level that should be used when invoking an
external entity. A safe call is less efficient, but guarantees to
leave the Haskell system in a state that allows callbacks from the
external code. In contrast, an unsafe call, while carrying less
overhead, must not trigger a callback into the Haskell system. If it
does, the system behaviour is undefined. The default for an invocation
is to be safe. Note that a callback into the Haskell system implies
that a garbage collection might be triggered after an external entity
was called, but before this call returns. Consequently, objects other
than stable pointers (cf. Section 5.6) may be moved or garbage
collected by the storage manager."

-- 
Adam Langley agl at imperialviolet.org http://www.imperialviolet.org


More information about the Haskell-Cafe mailing list