I noticed the following comment in my copy of Expert F# on page 379:
Passing and Processing Messages
A distinction is often made between shared-memory concurrency and message passing concurrency. The former is often more efficient on local machines and is covered in the section "Using Shared-Memory Concurrency" later in this chapter. The latter scales to systems where there is no shared memory, for example, distributed systems, and can also be used to avoid performance problems associated with shared memory.
I'm interested message passing concurrency between processes with no shared memory. All of the examples in Expert F# and on the internet which demonstrate how to use the MailboxProcessor contain some variation of this code:
let counter =
MailboxProcessor.Start(fun inbox ->
let rec loop n =
async {
do printfn "n = %d, waiting... " n
let! msg = inbox.Receive()
match msg with
| -1 ->
do printfn "'Til the bitter end..."
return ()
| n -> return! loop(n + msg)
}
loop 0)
counter.Post(20)
counter.Post(50)
counter.Post(-1) // kill mailbox
In other words, you have to have a handle on your MailboxProcessor in shared-memory before you can post messages to its channel. This isn't Erlang-style concurrency as far as I know it, since you can only post messages to MailboxProcessors in the same process (note: process, not thread).
Is it possible for one MailboxProcessor in one process to send messages to another MailboxProcessor process? If so, could you provide a sample?