init
initializes the system and creates the master process. master_init
, if
specified, is called in the master process and may be used for cleanup/initialization
such as closing file descriptors. init
should be called before any threads are
created. If your program daemonizes, call init
after you daemonize, but before you
start the async scheduler. init
may only be called once.
If cluster
is specified, and it specifies a set of host names or ips that you can
ssh to without a password, and have permission to run programs on, then a master
process will also be started on every machine in the cluster, and worker processes may
be spawned on any machine in the cluster. Note that in ord
shutdown
requests that the master process kill all workers and then shutdown. It
then waits for the master process to exit. shutdown
returns Ok ()
when the master
exits without problems; otherwise it returns an error.
Run the specified closure in another process and return its result.
If where
is specified, it controls which machine the process is spawned on. The
default is the local machine. You must have passed a list of machines to init in order
to use `On, or `Random_on. An exception will be raised if you try to use a machine you
didn't pass to init.
The closure you pass may not contain custom blocks with unimplemented serialization functions or Abstract values. Anything you can't pass to Marshal, you can't pass to spawn.
spawn f
spawns a process running f
, supplying f
a hub that it may use to
communicate with other processes. f
should listen to the hub to receive messages
from the clients. spawn
returns a channel connected to f
's hub, and a deferred
that will become determined if f
returns.
There is no guarantee that the deferred returned by this function will become determined before the spawned process runs, as such the following code is a race, and may never return.
| spawn (fun hub -> Hub.send_to_all hub `Hello; Deferred.never ()) | >>= fun (channel, _) -> | Channel.read channel | >>= fun `Hello -> | ...
It IS however guaranteed that the spawned process is listening when the deferred returned by this function is returned, it is theirfore recommended that the spawning process initiate the first communication.
If where
is specified, it controls which machine the process is spawned on. The
default is the local machine. You must have passed a list of machines to init in order
to use `On, or `Random_on. An exception will be raised if you try to use a machine you
didn't pass to init.
The closure you pass may not contain custom blocks with unimplemented serialization functions or Abstract values. Anything you can't pass to Marshal, you can't pass to spawn.
returns true if this is a worker machine. See the notes on running on multiple machines in Std.ml.