ConcurrentLua logo

ConcurrentLua

Concurrency Oriented Programming in Lua

Reference

Processes

spawn(body, ...)

Creates a process which will execute the body function. Any extra arguments can be passed to the executing function. The PID of the new process is returned. In case of error nil and an error message are returned.

spawn(node, body, ...)

Creates a process in a remote node which is a string in the format 'nodename@hostname' and the new process will execute the body function. The PID of the new process is returned. In case of error nil and an error message are returned.

self()

Returns the PID of the calling process.

isalive(process)

Checks if the process, which can be specified by PID or by its registered string name, is alive. Returns true if the process is alive, and false otherwise.

exit(reason)

Exits abnormally the calling process with the specified reason string as a cause of exit.

Messages

receive([timeout])

Receives the next message in the mailbox of the calling process. If the mailbox is empty it waits indefinitely for a message to arrive, unless a timeout number in milliseconds is specified. A message of any type, that depends on what was sent, is returned.

send(process, message)

Sends to the destination process a message which can be one of: boolean, number, string, table, function. Returns true if the message was send successfully, and false if not.

Scheduling

sleep(time)

Suspends implicitly the calling process for the specified time, the number of milliseconds.

loop([timeout])

Calls the system's infinite loop which executes the process scheduler until all the processes have terminated, or unless the specified timeout, the number of milliseconds, has expired.

interrupt()

Interrupts the infinite loop of the process scheduler.

step([timeout])

Executes one step of the process scheduler unless the specified timeout, the number of milliseconds, has expired.

tick()

Forwards the system's clock by one tick.

Options

setoption(key, value)

Sets the key string option to the specified value, the type of which depends on the option.

getoption(key)

Returns the value of the key string option.

Node

init(node)

Makes the runtime system a distributed node. The first argument is the name string of the node, which can be either in 'nodename' or 'nodename@hostname' format.

If the 'shortnames' option is set to true, then short names are used instead of fully qualified domain names. If the 'connectall' option is set to false, then a fully connected virtual network between the nodes will not be maintained.

shutdown()

Makes the runtime system stop being a distributed node.

node()

Returns the name of the node the calling process is running on.

nodes()

Returns a table with the nodes that the node the calling process is running on is connected to.

isnodealive()

Returns true if the local node has been initialized, and false otherwise.

monitornode(node)

The calling process starts monitoring the specified node, which is a string of the format 'nodename@hostname'.

demonitornode(node)

The calling process stops monitoring the specified node, which is a string of the format 'nodename@hostname'.

Security

setcookie(secret)

Sets the pre-shared secret key, a string, also known as the magic cookie, that will be used for node authentication.

getcookie()

Returns the pre-shared secret key, also known as the magic cookie, that is being used for node authentication.

Registering

register(name, pid)

Registers the name string for the given process pid.

unregister(name)

Unregisters the process with the name string.

whereis(name)

Returns the PID of the process with the registered name string.

registered()

Returns a table with all the registered process names.

Linking

link(process)

The calling process gets linked with the specified process, which can be either a PID, a registered name, or a remote process. A remote process is a table with two elements, the remote process PID or registered name and the node's name in the format 'nodename@hostname' .

The 'trapexit' option can be set to true, if exit signals between linked processes are to be trapped.

unlink(process)

The calling process gets unlinked with the specified process, which can be either a PID, a registered name, or a remote process. A remote process is a table with two elements, the remote process PID or registered name and the node's name in the format 'nodename@hostname'.

spawnlink(body, ...)

Creates a process which will execute the body function and the calling function also gets linked to the new process. Any extra arguments can be passed to the executing function. The PID of the new process is returned. In case of error nil and an error message are returned.

The 'trapexit' option can be set to true, if exit signals between linked processes are to be trapped.

spawnlink(node, body, ...)

Creates a process in a remote node which is a string in the format 'nodename@hostname', the new process will execute the body function, and also the calling process gets linked to the newly created process. The PID of the new process is returned. In case of error nil and an error message are returned.

The 'trapexit' option can set to true, if exit signals between linked processes are to be trapped.

Monitoring

monitor(process)

The calling process starts monitoring the specified process, which can be either a PID, a registered name, or a remote process. A remote process is a table with two elements, the remote process PID or registered name and the node's name in the format 'nodename@hostname'.

demonitor(process)

The calling process stops monitoring the specified process, which can be either a PID, a registered name, or a remote process. A remote process is a table with two elements, the remote process PID or registered name and the node's name in the format 'nodename@hostname'.

spawnmonitor(body, ...)

Creates a process which will execute the body function and the calling function also starts monitoring the new process. Any extra arguments can be passed to the executing function. The PID of the new process is returned. In case of error nil and an error message are returned.

spawnmonitor(node, body, ...)

Creates a process in a remote node which is a string in the format 'nodename@hostname', the new process will execute the body function, and also the calling process starts monitoring the newly created process. The PID of the new process is returned. In case of error nil and an error message are returned.