Thread-Safety through FFI

Simon Marlow
Thu, 25 Oct 2001 11:12:47 +0100

> >It isn't safe to call foreign exported
> >functions from more that one OS thread simultaneously.
> OK, can I call a foreign exported function from some other=20
> thread while=20
> the main thread is in 'foreign import' native code? I could=20
> have calls to=20
> the foreign exported function block until the main thread called a=20
> special foreign imported 'yield' function.

This might work, but no guarantees.  Make sure that at least the foreign
import yield doesn't have an unsafe annotation.  The reason I'm slightly
worried is that the RTS isn't written to be used in a threaded
environment - it doesn't use thread-friendly library calls, and I don't
even want to think about signal handling.