Thread-Safety through FFI

Ashley Yakeley ashley@semantic.org
Tue, 23 Oct 2001 23:34:18 -0700


Is there a way of calling exported 'dynamic export' functions in a 
thread-safe manner? I have this problem in JVM-Bridge...

This is what the main thread does, from Haskell:

1. starts the Java VM, which starts a bunch of other threads, including 
the AWT thread;
2. creates a pointer to a some IO function 'paint', using a 'dynamic 
export' callback-maker;
3. creates a new Java Frame (i.e. a GUI window) with the function-pointer;
4. repeatedly calls the Java Thread.yield function for 20 seconds.
(the program then ends)

Now, once the Java Frame has been created, the AWT thread will 
occasionally call the 'paint' method, which ends up calling the 
function-pointer. However, it seems GHC 5.02 'dynamic export' calls are 
not thread-safe, and sooner or later it crashes, either with a seg 
violation or a complaint about unknown closure types.

-- 
Ashley Yakeley, Seattle WA