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