Thread-Safety through FFI

Ashley Yakeley ashley@semantic.org
Wed, 24 Oct 2001 16:51:16 -0700


At 2001-10-24 02:52, Simon Marlow wrote:

>If you're talking about OS threads (eg. POSIX threads), 

Yes

>then GHC's RTS certainly isn't thread safe.  

Good. This means I know why it's crashing...

>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 thread while 
the main thread is in 'foreign import' native code? I could have calls to 
the foreign exported function block until the main thread called a 
special foreign imported 'yield' function.

The alternative is to have all Haskell in one thread, which means other 
threads would have to queue up calls to foreign exported functions, which 
would get executed by the main thread whenever it called 'yield'.


-- 
Ashley Yakeley, Seattle WA