git.iko.soy/distributed-process
on master help sign in
Fix bug in spawnChannelLocal
2f2ed0aEdsko de Vries
distributed-process/src/Control/Distributed/Process.hs+10−3
@@ -114,6 +114,7 @@ import Data.Typeable (Typeable)
114import Control.Monad.IO.Class (liftIO)
114import Control.Monad.IO.Class (liftIO)
115import Control.Applicative ((<$>))
115import Control.Applicative ((<$>))
116import Control.Monad.Reader (ask)
116import Control.Monad.Reader (ask)
117+import Control.Concurrent.MVar (newEmptyMVar, takeMVar, putMVar)
117import Control.Distributed.Static
118import Control.Distributed.Static
118 ( Closure
119 ( Closure
119 , closure
120 , closure
@@ -410,6 +411,12 @@ spawnChannelLocal :: Serializable a
410 -> Process (SendPort a)
411 -> Process (SendPort a)
411spawnChannelLocal proc = do
412spawnChannelLocal proc = do
412 node <- processNode <$> ask
413 node <- processNode <$> ask
413− (sport, rport) <- newChan
414+ liftIO $ do
415+ mvar <- newEmptyMVar
414− _ <- liftIO $ forkProcess node (proc rport)
416+ forkProcess node $ do
415− return sport
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