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
43 -- * Advanced messaging
63 -- * Process management
72 , ProcessTerminationException(..)
73 , ProcessRegistrationException(..)
79 -- * Monitoring and linking
91 , MonitorRef -- opaque
92 , ProcessLinkException(..)
93 , NodeLinkException(..)
94 , PortLinkException(..)
95 , ProcessMonitorNotification(..)
96 , NodeMonitorNotification(..)
97 , PortMonitorNotification(..)
114 , registerRemoteAsync
115 , reregisterRemoteAsync
116 , unregisterRemoteAsync
121 -- * Exception handling
138 -- * Local versions of 'spawn'
146#if ! MIN_VERSION_base(4,6,0)
147import Prelude hiding (catch)
150import Control.Monad.IO.Class (liftIO)
151import Control.Applicative ((<$>))
152import Control.Monad.Reader (ask)
153import Control.Concurrent.MVar (newEmptyMVar, takeMVar, putMVar)
154import Control.Distributed.Static
160import Control.Distributed.Process.Internal.Types
165 , ProcessMonitorNotification(..)
166 , NodeMonitorNotification(..)
167 , PortMonitorNotification(..)
168 , ProcessLinkException(..)
169 , NodeLinkException(..)
170 , PortLinkException(..)
171 , ProcessRegistrationException(..)
180 , LocalProcess(processNode)
183import Control.Distributed.Process.Serializable (Serializable)
184import Control.Distributed.Process.Internal.Primitives
197 -- Advanced messaging
216 -- Process management
218 , ProcessTerminationException(..)
228 -- Monitoring and linking
248 , registerRemoteAsync
249 , reregisterRemoteAsync
250 , unregisterRemoteAsync
256 -- Exception handling
274import Control.Distributed.Process.Node (forkProcess)
275import Control.Distributed.Process.Internal.Spawn
276 ( -- Spawning Processes/Channels
287-- 1. 'send' never fails. If you want to know that the remote process received
288-- your message, you will need to send an explicit acknowledgement. If you
289-- want to know when the remote process failed, you will need to monitor
290-- that remote process.
292-- 2. 'send' may block (when the system TCP buffers are full, while we are
293-- trying to establish a connection to the remote endpoint, etc.) but its
294-- return does not imply that the remote process received the message (much
295-- less processed it). When 'send' targets a local process, it is dispatched
296-- via the node controller however, in which cases it will /not/ block. This
297-- isn't part of the semantics, so it should be ok. The ordering is maintained
298-- because the ctrlChannel still has FIFO semantics with regards interactions
299-- between two disparate forkIO threads.
301-- 3. Message delivery is reliable and ordered. That means that if process A
302-- sends messages m1, m2, m3 to process B, B will either arrive all three
303-- messages in order (m1, m2, m3) or a prefix thereof; messages will not be
304-- 'missing' (m1, m3) or reordered (m1, m3, m2)
306-- In order to guarantee (3), we stipulate that
308-- 3a. We do not garbage collect connections because Network.Transport provides
309-- ordering guarantees only *per connection*.
311-- 3b. Once a connection breaks, we have no way of knowing which messages
312-- arrived and which did not; hence, once a connection fails, we assume the
313-- remote process to be forever unreachable. Otherwise we might sent m1 and
314-- m2, get notified of the broken connection, reconnect, send m3, but only
317-- 3c. As a consequence of (3b) we should not reuse PIDs. If a process dies,
318-- we consider it forever unreachable. Hence, new processes should get new
319-- IDs or they too would be considered unreachable.
321-- Main reference for Cloud Haskell is
323-- [1] "Towards Haskell in the Cloud", Jeff Epstein, Andrew Black and Simon
325-- http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/remote.pdf
327-- The precise semantics for message passing is based on
329-- [2] "A Unified Semantics for Future Erlang", Hans Svensson, Lars-Ake Fredlund
330-- and Clara Benac Earle (not freely available online, unfortunately)
332-- Some pointers to related documentation about Erlang, for comparison and
335-- [3] "Programming Distributed Erlang Applications: Pitfalls and Recipes",
336-- Hans Svensson and Lars-Ake Fredlund
337-- http://man.lupaworld.com/content/develop/p37-svensson.pdf
338-- [4] The Erlang manual, sections "Message Sending" and "Send"
339-- http://www.erlang.org/doc/reference_manual/processes.html#id82409
340-- http://www.erlang.org/doc/reference_manual/expressions.html#send
341-- [5] Questions "Is the order of message reception guaranteed?" and
342-- "If I send a message, is it guaranteed to reach the receiver?" of
344-- http://www.erlang.org/faq/academic.html
345-- [6] "Delivery of Messages", post on erlang-questions
346-- http://erlang.org/pipermail/erlang-questions/2012-February/064767.html
348--------------------------------------------------------------------------------
349-- Local versions of spawn --
350--------------------------------------------------------------------------------
352-- | Spawn a process on the local node
353spawnLocal :: Process () -> Process ProcessId
355 node <- processNode <$> ask
356 liftIO $ forkProcess node proc
358-- | Create a new typed channel, spawn a process on the local node, passing it
359-- the receive port, and return the send port
360spawnChannelLocal :: Serializable a
361 => (ReceivePort a -> Process ())
362 -> Process (SendPort a)
363spawnChannelLocal proc = do
364 node <- processNode <$> ask
367 _ <- forkProcess node $ do
368 -- It is important that we allocate the new channel in the new process,
369 -- because otherwise it will be associated with the wrong process ID
370 (sport, rport) <- newChan
371 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