3This is an implementation of Cloud Haskell, as described in
4/Towards Haskell in the Cloud/ by Jeff Epstein, Andrew Black, and Simon
6<http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/>),
7although some of the details are different. The precise message passing
8semantics are based on /A unified semantics for future Erlang/ by Hans
9Svensson, Lars-Åke Fredlund and Clara Benac Earle.
11For a detailed description of the package and other reference materials,
12please see the distributed-process wiki page on github:
13<https://github.com/haskell-distributed/distributed-process/wiki>.
16module Control.Distributed.Process
24 , liftIO -- Reexported for convenience
39 -- * Unsafe messaging variants
44 -- * Advanced messaging
66 -- * Process management
75 , ProcessTerminationException(..)
76 , ProcessRegistrationException(..)
82 -- * Monitoring and linking
94 , MonitorRef -- opaque
95 , ProcessLinkException(..)
96 , NodeLinkException(..)
97 , PortLinkException(..)
98 , ProcessMonitorNotification(..)
99 , NodeMonitorNotification(..)
100 , PortMonitorNotification(..)
117 , registerRemoteAsync
118 , reregisterRemoteAsync
119 , unregisterRemoteAsync
124 -- * Exception handling
141 -- * Local versions of 'spawn'
149#if ! MIN_VERSION_base(4,6,0)
150import Prelude hiding (catch)
153import Control.Monad.IO.Class (liftIO)
154import Control.Applicative ((<$>))
155import Control.Monad.Reader (ask)
156import Control.Concurrent.MVar (newEmptyMVar, takeMVar, putMVar)
157import Control.Distributed.Static
163import Control.Distributed.Process.Internal.Types
168 , ProcessMonitorNotification(..)
169 , NodeMonitorNotification(..)
170 , PortMonitorNotification(..)
171 , ProcessLinkException(..)
172 , NodeLinkException(..)
173 , PortLinkException(..)
174 , ProcessRegistrationException(..)
183 , LocalProcess(processNode)
186import Control.Distributed.Process.Serializable (Serializable)
187import Control.Distributed.Process.Internal.Primitives
200 -- Advanced messaging
222 -- Process management
224 , ProcessTerminationException(..)
234 -- Monitoring and linking
254 , registerRemoteAsync
255 , reregisterRemoteAsync
256 , unregisterRemoteAsync
262 -- Exception handling
280import Control.Distributed.Process.Node (forkProcess)
281import Control.Distributed.Process.Internal.Spawn
282 ( -- Spawning Processes/Channels
293-- 1. 'send' never fails. If you want to know that the remote process received
294-- your message, you will need to send an explicit acknowledgement. If you
295-- want to know when the remote process failed, you will need to monitor
296-- that remote process.
298-- 2. 'send' may block (when the system TCP buffers are full, while we are
299-- trying to establish a connection to the remote endpoint, etc.) but its
300-- return does not imply that the remote process received the message (much
301-- less processed it). When 'send' targets a local process, it is dispatched
302-- via the node controller however, in which cases it will /not/ block. This
303-- isn't part of the semantics, so it should be ok. The ordering is maintained
304-- because the ctrlChannel still has FIFO semantics with regards interactions
305-- between two disparate forkIO threads.
307-- 3. Message delivery is reliable and ordered. That means that if process A
308-- sends messages m1, m2, m3 to process B, B will either arrive all three
309-- messages in order (m1, m2, m3) or a prefix thereof; messages will not be
310-- 'missing' (m1, m3) or reordered (m1, m3, m2)
312-- In order to guarantee (3), we stipulate that
314-- 3a. We do not garbage collect connections because Network.Transport provides
315-- ordering guarantees only *per connection*.
317-- 3b. Once a connection breaks, we have no way of knowing which messages
318-- arrived and which did not; hence, once a connection fails, we assume the
319-- remote process to be forever unreachable. Otherwise we might sent m1 and
320-- m2, get notified of the broken connection, reconnect, send m3, but only
323-- 3c. As a consequence of (3b) we should not reuse PIDs. If a process dies,
324-- we consider it forever unreachable. Hence, new processes should get new
325-- IDs or they too would be considered unreachable.
327-- Main reference for Cloud Haskell is
329-- [1] "Towards Haskell in the Cloud", Jeff Epstein, Andrew Black and Simon
331-- http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/remote.pdf
333-- The precise semantics for message passing is based on
335-- [2] "A Unified Semantics for Future Erlang", Hans Svensson, Lars-Ake Fredlund
336-- and Clara Benac Earle (not freely available online, unfortunately)
338-- Some pointers to related documentation about Erlang, for comparison and
341-- [3] "Programming Distributed Erlang Applications: Pitfalls and Recipes",
342-- Hans Svensson and Lars-Ake Fredlund
343-- http://man.lupaworld.com/content/develop/p37-svensson.pdf
344-- [4] The Erlang manual, sections "Message Sending" and "Send"
345-- http://www.erlang.org/doc/reference_manual/processes.html#id82409
346-- http://www.erlang.org/doc/reference_manual/expressions.html#send
347-- [5] Questions "Is the order of message reception guaranteed?" and
348-- "If I send a message, is it guaranteed to reach the receiver?" of
350-- http://www.erlang.org/faq/academic.html
351-- [6] "Delivery of Messages", post on erlang-questions
352-- http://erlang.org/pipermail/erlang-questions/2012-February/064767.html
354--------------------------------------------------------------------------------
355-- Local versions of spawn --
356--------------------------------------------------------------------------------
358-- | Spawn a process on the local node
359spawnLocal :: Process () -> Process ProcessId
361 node <- processNode <$> ask
362 liftIO $ forkProcess node proc
364-- | Create a new typed channel, spawn a process on the local node, passing it
365-- the receive port, and return the send port
366spawnChannelLocal :: Serializable a
367 => (ReceivePort a -> Process ())
368 -> Process (SendPort a)
369spawnChannelLocal proc = do
370 node <- processNode <$> ask
373 _ <- forkProcess node $ do
374 -- It is important that we allocate the new channel in the new process,
375 -- because otherwise it will be associated with the wrong process ID
376 (sport, rport) <- newChan
377 liftIO $ putMVar mvar sport
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list