git.iko.soy/distributed-process
on master help sign in
Fix bug in spawnChannelLocal
commit2f2ed0a394059103b5fe84d54c4f9c7f849fbea1 authorEdsko de Vries <edsko@edsko.net> dateTue 2 Oct 2012, 17:54 (14 years ago) parentae5150e
1 file changed+10−3
distributed-process/src/Control/Distributed/Process.hs+10−3
distributed-process/src/Control/Distributed/Process.hs+10−3
@@ -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