git.iko.soy/distributed-process
on master help sign in
Fix race in spawn. DP-99 #resolve

Signed-off-by: Tim Watson <watson.timothy@gmail.com>

commita2587575410ca8e5070c59bbd3e6e8bd0f10fee9 authorTim Watson <watson.timothy@gmail.com> dateMon 19 Jan 2015, 17:29 (12 years ago) parented0416b10d72bb
2 files changed+8−7
src/Control/Distributed/Process/Internal/Closure/BuiltIn.hs+6−5 src/Control/Distributed/Process/Internal/Spawn.hs+2−2
src/Control/Distributed/Process/Internal/Closure/BuiltIn.hs+6−5
@@ -28,7 +28,7 @@ module Control.Distributed.Process.Internal.Closure.BuiltIn
2828 , cpExpect
2929 , cpNewChan
3030 -- * Support for some CH operations
31− , cpDelay
31+ , cpDelayed
3232 , cpEnableTraceRemote
3333 ) where
3434
@@ -295,19 +295,20 @@ cpEnableTraceRemote =
295295-- | @delay them p@ is a process that waits for a signal (a message of type @()@)
296296-- from 'them' (origin is not verified) before proceeding as @p@. In order to
297297-- 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.
299299delay :: ProcessId -> Process () -> Process ()
300300delay them p = do
301301 ref <- monitor them
302302 let sameRef (ProcessMonitorNotification ref' _ _) = ref == ref'
303303 receiveWait [
304− match $ \() -> unmonitor ref >> p
304+ match $ \() -> unmonitor ref
305305 , matchIf sameRef $ \_ -> return ()
306306 ]
307+ p
307308
308309-- | 'CP' version of 'delay'
309−cpDelay :: ProcessId -> Closure (Process ()) -> Closure (Process ())
310−cpDelay = closureApply . cpDelay'
310+cpDelayed :: ProcessId -> Closure (Process ()) -> Closure (Process ())
311+cpDelayed = closureApply . cpDelay'
311312 where
312313 cpDelay' :: ProcessId -> Closure (Process () -> Process ())
313314 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
3737 , cpLink
3838 , cpSend
3939 , cpNewChan
40− , cpDelay
40+ , cpDelayed
4141 )
4242import Control.Distributed.Process.Internal.Primitives
4343 ( -- Basic messaging
@@ -65,7 +65,7 @@ spawn :: NodeId -> Closure (Process ()) -> Process ProcessId
6565spawn nid proc = do
6666 us <- getSelfPid
6767 mRef <- monitorNode nid
68− sRef <- spawnAsync nid (cpDelay us proc)
68+ sRef <- spawnAsync nid (cpDelayed us proc)
6969 receiveWait [
7070 matchIf (\(DidSpawn ref _) -> ref == sRef) $ \(DidSpawn _ pid) -> do
7171 unmonitor mRef