4This is an implementation of Cloud Haskell, as described in
5/Towards Haskell in the Cloud/ by Jeff Epstein, Andrew Black, and Simon
7<http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/>),
8although some of the details are different. The precise message passing
9semantics are based on /A unified semantics for future Erlang/ by Hans
10Svensson, Lars-Åke Fredlund and Clara Benac Earle.
12For a detailed description of the package and other reference materials,
13please see the distributed-process wiki page on github:
14<https://github.com/haskell-distributed/distributed-process/wiki>.
17module Control.Distributed.Process
25 , liftIO -- Reexported for convenience
40 -- * Unsafe messaging variants
45 -- * Advanced messaging
70 -- * Process management
79 , ProcessTerminationException(..)
80 , ProcessRegistrationException(..)
89 -- * Monitoring and linking
101 , MonitorRef -- opaque
102 , ProcessLinkException(..)
103 , NodeLinkException(..)
104 , PortLinkException(..)
105 , ProcessMonitorNotification(..)
106 , NodeMonitorNotification(..)
107 , PortMonitorNotification(..)
124 , registerRemoteAsync
125 , reregisterRemoteAsync
126 , unregisterRemoteAsync
131 -- * Exception handling
148 -- * Local versions of 'spawn'
156#if ! MIN_VERSION_base(4,6,0)
157import Prelude hiding (catch)
160import Control.Monad.IO.Class (liftIO)
161import Control.Applicative ((<$>))
162import Control.Monad.Reader (ask)
163import Control.Concurrent.MVar (newEmptyMVar, takeMVar, putMVar)
164import Control.Distributed.Static
170import Control.Distributed.Process.Internal.Types
175 , ProcessMonitorNotification(..)
176 , NodeMonitorNotification(..)
177 , PortMonitorNotification(..)
178 , ProcessLinkException(..)
179 , NodeLinkException(..)
180 , PortLinkException(..)
181 , ProcessRegistrationException(..)
190 , LocalProcess(processNode)
193import Control.Distributed.Process.Serializable (Serializable)
194import Control.Distributed.Process.Internal.Primitives
207 -- Advanced messaging
232 -- Process management
234 , ProcessTerminationException(..)
247 -- Monitoring and linking
267 , registerRemoteAsync
268 , reregisterRemoteAsync
269 , unregisterRemoteAsync
275 -- Exception handling
293import Control.Distributed.Process.Node (forkProcess)
294import Control.Distributed.Process.Internal.Spawn
295 ( -- Spawning Processes/Channels
306-- 1. 'send' never fails. If you want to know that the remote process received
307-- your message, you will need to send an explicit acknowledgement. If you
308-- want to know when the remote process failed, you will need to monitor
309-- that remote process.
311-- 2. 'send' may block (when the system TCP buffers are full, while we are
312-- trying to establish a connection to the remote endpoint, etc.) but its
313-- return does not imply that the remote process received the message (much
314-- less processed it). When 'send' targets a local process, it is dispatched
315-- via the node controller however, in which cases it will /not/ block. This
316-- isn't part of the semantics, so it should be ok. The ordering is maintained
317-- because the ctrlChannel still has FIFO semantics with regards interactions
318-- between two disparate forkIO threads.
320-- 3. Message delivery is reliable and ordered. That means that if process A
321-- sends messages m1, m2, m3 to process B, B will either arrive all three
322-- messages in order (m1, m2, m3) or a prefix thereof; messages will not be
323-- 'missing' (m1, m3) or reordered (m1, m3, m2)
325-- In order to guarantee (3), we stipulate that
327-- 3a. We do not garbage collect connections because Network.Transport provides
328-- ordering guarantees only *per connection*.
330-- 3b. Once a connection breaks, we have no way of knowing which messages
331-- arrived and which did not; hence, once a connection fails, we assume the
332-- remote process to be forever unreachable. Otherwise we might sent m1 and
333-- m2, get notified of the broken connection, reconnect, send m3, but only
336-- 3c. As a consequence of (3b) we should not reuse PIDs. If a process dies,
337-- we consider it forever unreachable. Hence, new processes should get new
338-- IDs or they too would be considered unreachable.
340-- Main reference for Cloud Haskell is
342-- [1] "Towards Haskell in the Cloud", Jeff Epstein, Andrew Black and Simon
344-- http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/remote.pdf
346-- The precise semantics for message passing is based on
348-- [2] "A Unified Semantics for Future Erlang", Hans Svensson, Lars-Ake Fredlund
349-- and Clara Benac Earle (not freely available online, unfortunately)
351-- Some pointers to related documentation about Erlang, for comparison and
354-- [3] "Programming Distributed Erlang Applications: Pitfalls and Recipes",
355-- Hans Svensson and Lars-Ake Fredlund
356-- http://man.lupaworld.com/content/develop/p37-svensson.pdf
357-- [4] The Erlang manual, sections "Message Sending" and "Send"
358-- http://www.erlang.org/doc/reference_manual/processes.html#id82409
359-- http://www.erlang.org/doc/reference_manual/expressions.html#send
360-- [5] Questions "Is the order of message reception guaranteed?" and
361-- "If I send a message, is it guaranteed to reach the receiver?" of
363-- http://www.erlang.org/faq/academic.html
364-- [6] "Delivery of Messages", post on erlang-questions
365-- http://erlang.org/pipermail/erlang-questions/2012-February/064767.html
367--------------------------------------------------------------------------------
368-- Local versions of spawn --
369--------------------------------------------------------------------------------
371-- | Spawn a process on the local node
372spawnLocal :: Process () -> Process ProcessId
374 node <- processNode <$> ask
375 liftIO $ forkProcess node proc
377-- | Create a new typed channel, spawn a process on the local node, passing it
378-- the receive port, and return the send port
379spawnChannelLocal :: Serializable a
380 => (ReceivePort a -> Process ())
381 -> Process (SendPort a)
382spawnChannelLocal proc = do
383 node <- processNode <$> ask
386 _ <- forkProcess node $ do
387 -- It is important that we allocate the new channel in the new process,
388 -- because otherwise it will be associated with the wrong process ID
389 (sport, rport) <- newChan
390 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