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