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
69 -- * Process management
78 , ProcessTerminationException(..)
79 , ProcessRegistrationException(..)
88 -- * Monitoring and linking
100 , MonitorRef -- opaque
101 , ProcessLinkException(..)
102 , NodeLinkException(..)
103 , PortLinkException(..)
104 , ProcessMonitorNotification(..)
105 , NodeMonitorNotification(..)
106 , PortMonitorNotification(..)
123 , registerRemoteAsync
124 , reregisterRemoteAsync
125 , unregisterRemoteAsync
130 -- * Exception handling
147 -- * Local versions of 'spawn'
155#if ! MIN_VERSION_base(4,6,0)
156import Prelude hiding (catch)
159import Control.Monad.IO.Class (liftIO)
160import Control.Applicative ((<$>))
161import Control.Monad.Reader (ask)
162import Control.Concurrent.MVar (newEmptyMVar, takeMVar, putMVar)
163import Control.Distributed.Static
169import Control.Distributed.Process.Internal.Types
174 , ProcessMonitorNotification(..)
175 , NodeMonitorNotification(..)
176 , PortMonitorNotification(..)
177 , ProcessLinkException(..)
178 , NodeLinkException(..)
179 , PortLinkException(..)
180 , ProcessRegistrationException(..)
189 , LocalProcess(processNode)
192import Control.Distributed.Process.Serializable (Serializable)
193import Control.Distributed.Process.Internal.Primitives
206 -- Advanced messaging
231 -- Process management
233 , ProcessTerminationException(..)
246 -- Monitoring and linking
266 , registerRemoteAsync
267 , reregisterRemoteAsync
268 , unregisterRemoteAsync
274 -- Exception handling
292import Control.Distributed.Process.Node (forkProcess)
293import Control.Distributed.Process.Internal.Spawn
294 ( -- Spawning Processes/Channels
305-- 1. 'send' never fails. If you want to know that the remote process received
306-- your message, you will need to send an explicit acknowledgement. If you
307-- want to know when the remote process failed, you will need to monitor
308-- that remote process.
310-- 2. 'send' may block (when the system TCP buffers are full, while we are
311-- trying to establish a connection to the remote endpoint, etc.) but its
312-- return does not imply that the remote process received the message (much
313-- less processed it). When 'send' targets a local process, it is dispatched
314-- via the node controller however, in which cases it will /not/ block. This
315-- isn't part of the semantics, so it should be ok. The ordering is maintained
316-- because the ctrlChannel still has FIFO semantics with regards interactions
317-- between two disparate forkIO threads.
319-- 3. Message delivery is reliable and ordered. That means that if process A
320-- sends messages m1, m2, m3 to process B, B will either arrive all three
321-- messages in order (m1, m2, m3) or a prefix thereof; messages will not be
322-- 'missing' (m1, m3) or reordered (m1, m3, m2)
324-- In order to guarantee (3), we stipulate that
326-- 3a. We do not garbage collect connections because Network.Transport provides
327-- ordering guarantees only *per connection*.
329-- 3b. Once a connection breaks, we have no way of knowing which messages
330-- arrived and which did not; hence, once a connection fails, we assume the
331-- remote process to be forever unreachable. Otherwise we might sent m1 and
332-- m2, get notified of the broken connection, reconnect, send m3, but only
335-- 3c. As a consequence of (3b) we should not reuse PIDs. If a process dies,
336-- we consider it forever unreachable. Hence, new processes should get new
337-- IDs or they too would be considered unreachable.
339-- Main reference for Cloud Haskell is
341-- [1] "Towards Haskell in the Cloud", Jeff Epstein, Andrew Black and Simon
343-- http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/remote.pdf
345-- The precise semantics for message passing is based on
347-- [2] "A Unified Semantics for Future Erlang", Hans Svensson, Lars-Ake Fredlund
348-- and Clara Benac Earle (not freely available online, unfortunately)
350-- Some pointers to related documentation about Erlang, for comparison and
353-- [3] "Programming Distributed Erlang Applications: Pitfalls and Recipes",
354-- Hans Svensson and Lars-Ake Fredlund
355-- http://man.lupaworld.com/content/develop/p37-svensson.pdf
356-- [4] The Erlang manual, sections "Message Sending" and "Send"
357-- http://www.erlang.org/doc/reference_manual/processes.html#id82409
358-- http://www.erlang.org/doc/reference_manual/expressions.html#send
359-- [5] Questions "Is the order of message reception guaranteed?" and
360-- "If I send a message, is it guaranteed to reach the receiver?" of
362-- http://www.erlang.org/faq/academic.html
363-- [6] "Delivery of Messages", post on erlang-questions
364-- http://erlang.org/pipermail/erlang-questions/2012-February/064767.html
366--------------------------------------------------------------------------------
367-- Local versions of spawn --
368--------------------------------------------------------------------------------
370-- | Spawn a process on the local node
371spawnLocal :: Process () -> Process ProcessId
373 node <- processNode <$> ask
374 liftIO $ forkProcess node proc
376-- | Create a new typed channel, spawn a process on the local node, passing it
377-- the receive port, and return the send port
378spawnChannelLocal :: Serializable a
379 => (ReceivePort a -> Process ())
380 -> Process (SendPort a)
381spawnChannelLocal proc = do
382 node <- processNode <$> ask
385 _ <- forkProcess node $ do
386 -- It is important that we allocate the new channel in the new process,
387 -- because otherwise it will be associated with the wrong process ID
388 (sport, rport) <- newChan
389 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