git.iko.soy/distributed-process
on master help sign in
Fix race in spawn. DP-99 #resolve
a258757Tim Watson
src/Control/Distributed/Process/Internal/Closure/BuiltIn.hs+6−5
@@ -28,7 +28,7 @@ module Control.Distributed.Process.Internal.Closure.BuiltIn
28 , cpExpect
28 , cpExpect
29 , cpNewChan
29 , cpNewChan
30 -- * Support for some CH operations
30 -- * Support for some CH operations
31− , cpDelay
31+ , cpDelayed
32 , cpEnableTraceRemote
32 , cpEnableTraceRemote
33 ) where
33 ) where
34
34
@@ -295,19 +295,20 @@ cpEnableTraceRemote =
295-- | @delay them p@ is a process that waits for a signal (a message of type @()@)
295-- | @delay them p@ is a process that waits for a signal (a message of type @()@)
296-- from 'them' (origin is not verified) before proceeding as @p@. In order to
296-- from 'them' (origin is not verified) before proceeding as @p@. In order to
297-- avoid waiting forever, @delay them p@ monitors 'them'. If it receives a
297-- avoid waiting forever, @delay them p@ monitors 'them'. If it receives a
298−-- monitor message instead it simply terminates.
298+-- monitor message instead, it proceeds as @p@ too.
299delay :: ProcessId -> Process () -> Process ()
299delay :: ProcessId -> Process () -> Process ()
300delay them p = do
300delay them p = do
301 ref <- monitor them
301 ref <- monitor them
302 let sameRef (ProcessMonitorNotification ref' _ _) = ref == ref'
302 let sameRef (ProcessMonitorNotification ref' _ _) = ref == ref'
303 receiveWait [
303 receiveWait [
304− match $ \() -> unmonitor ref >> p
304+ match $ \() -> unmonitor ref
305 , matchIf sameRef $ \_ -> return ()
305 , matchIf sameRef $ \_ -> return ()
306 ]
306 ]
307+ p
307
308
308-- | 'CP' version of 'delay'
309-- | 'CP' version of 'delay'
309−cpDelay :: ProcessId -> Closure (Process ()) -> Closure (Process ())
310+cpDelayed :: ProcessId -> Closure (Process ()) -> Closure (Process ())
310−cpDelay = closureApply . cpDelay'
311+cpDelayed = closureApply . cpDelay'
311 where
312 where
312 cpDelay' :: ProcessId -> Closure (Process () -> Process ())
313 cpDelay' :: ProcessId -> Closure (Process () -> Process ())
313 cpDelay' pid = closure decoder (encode pid)
314 cpDelay' pid = closure decoder (encode pid)
src/Control/Distributed/Process/Internal/Spawn.hs+2−2
@@ -37,7 +37,7 @@ import Control.Distributed.Process.Internal.Closure.BuiltIn
37 , cpLink
37 , cpLink
38 , cpSend
38 , cpSend
39 , cpNewChan
39 , cpNewChan
40− , cpDelay
40+ , cpDelayed
41 )
41 )
42import Control.Distributed.Process.Internal.Primitives
42import Control.Distributed.Process.Internal.Primitives
43 ( -- Basic messaging
43 ( -- Basic messaging
@@ -65,7 +65,7 @@ spawn :: NodeId -> Closure (Process ()) -> Process ProcessId
65spawn nid proc = do
65spawn nid proc = do
66 us <- getSelfPid
66 us <- getSelfPid
67 mRef <- monitorNode nid
67 mRef <- monitorNode nid
68− sRef <- spawnAsync nid (cpDelay us proc)
68+ sRef <- spawnAsync nid (cpDelayed us proc)
69 receiveWait [
69 receiveWait [
70 matchIf (\(DidSpawn ref _) -> ref == sRef) $ \(DidSpawn _ pid) -> do
70 matchIf (\(DidSpawn ref _) -> ref == sRef) $ \(DidSpawn _ pid) -> do
71 unmonitor mRef
71 unmonitor mRef