@@ -114,6 +114,7 @@ import Data.Typeable (Typeable)
114114import Control.Monad.IO.Class (liftIO)
115115import Control.Applicative ((<$>))
116116import Control.Monad.Reader (ask)
117+import Control.Concurrent.MVar (newEmptyMVar, takeMVar, putMVar)
117118import Control.Distributed.Static
118119 ( Closure
119120 , closure
@@ -410,6 +411,12 @@ spawnChannelLocal :: Serializable a
410411 -> Process (SendPort a)
411412spawnChannelLocal proc = do
412413 node <- processNode <$> ask
413− (sport, rport) <- newChan
414− _ <- liftIO $ forkProcess node (proc rport)
415− return sport
414+ liftIO $ do
415+ mvar <- newEmptyMVar
416+ forkProcess node $ do
417+ -- It is important that we allocate the new channel in the new process,
418+ -- because otherwise it will be associated with the wrong process ID
419+ (sport, rport) <- newChan
420+ liftIO $ putMVar mvar sport
421+ proc rport
422+ takeMVar mvar