object
linda
Linda tuple-space implementation for process communication. Provides a server that acts as a shared blackboard where clients can write (out/1), read (rd/1), and remove (in/1) tuples. Uses threaded engines for the server implementation and the sockets library for network communication.
logtalk_load(linda(loader))static, context_switching_calls, threaded
Supported backends: ECLiPSe, GNU Prolog, SICStus Prolog, SWI-Prolog, and Trealla Prolog (requires both multi-threading and sockets support).
Linda operations: The basic operations are
out/1(write tuple),in/1(remove tuple, blocking),rd/1(read tuple, blocking),in_noblock/1(remove tuple, non-blocking), andrd_noblock/1(read tuple, non-blocking).Tuple matching: Tuples are matched using unification.
Blocking behavior: The
in/1andrd/1predicates block until a matching tuple is available. Thein_noblock/1andrd_noblock/1predicates fail immediately if no matching tuple is found.Multiple clients: Multiple clients can connect to the same server. A tuple removed by
in/1orin_noblock/1is only removed for one client.API compatibility: The API is inspired by the SICStus Prolog Linda library.
Network communication: Uses TCP sockets for client-server communication, allowing processes to run on different machines.
Public predicates
linda/0
Starts a Linda server on an automatically assigned port. The server address (Host:Port) is written to the current output stream. The predicate succeeds when all clients have disconnected after a shutdown request.
staticlinda - onelinda/1
Starts a Linda server with the given options. The predicate succeeds when all clients have disconnected after a shutdown request.
staticlinda(Options)linda(::)linda(+list) - one
Option
port(Port): UsePortas the server port. Must be an integer and an available port.Option
Address-Goal:Addressis unified withHost:PortandGoalis called when the server starts. Useful for saving the address or starting clients.Option
accept_hook(Client,Stream,Goal): When a client connects,Clientis unified with the client address,Streamwith the connection stream, andGoalis called. IfGoalfails, the connection is rejected.
linda_client/1
Connects to a Linda server at the given address (Host:Port).
staticlinda_client(Address)linda_client(+compound) - one_or_errorlinda_error(already_connected)linda_error(connection_failed(Error))close_client/0
Closes the connection to the Linda server.
staticclose_client - oneshutdown_server/0
Sends a shutdown signal to the server. The server stops accepting new connections but continues serving existing clients until they all disconnect. Call close_client/0 after this predicate.
staticshutdown_server - one_or_errorlinda_error(not_connected)linda_timeout/2
Gets or sets the client timeout. OldTime is unified with the current timeout and the timeout is set to NewTime. The timeout value is either off (no timeout, wait forever) or Seconds:Milliseconds.
staticlinda_timeout(OldTime,NewTime)linda_timeout(?compound,+compound) - oneout/1
Places the tuple Tuple in the tuple-space.
staticout(Tuple)out(+term) - onein/1
Removes a tuple matching Tuple from the tuple-space. Blocks if no matching tuple is available.
staticin(Tuple)in(?term) - onein_noblock/1
Removes a tuple matching Tuple from the tuple-space. Fails if no matching tuple is available.
staticin_noblock(Tuple)in_noblock(?term) - zero_or_onein/2
Removes a tuple matching one of the patterns in TupleList from the tuple-space. Tuple is unified with the matched tuple. Blocks if no matching tuple is available.
staticin(TupleList,Tuple)in(+list,?term) - onein_list/2
Removes a tuple matching one of the patterns in TupleList from the tuple-space. Tuple is unified with the matched tuple. Blocks if no matching tuple is available.
staticin_list(TupleList,Tuple)in_list(+list,?term) - onerd/1
Reads a tuple matching Tuple from the tuple-space without removing it. Blocks if no matching tuple is available.
staticrd(Tuple)rd(?term) - onerd_noblock/1
Reads a tuple matching Tuple from the tuple-space without removing it. Fails if no matching tuple is available.
staticrd_noblock(Tuple)rd_noblock(?term) - zero_or_onerd/2
Reads a tuple matching one of the patterns in TupleList from the tuple-space without removing it. Tuple is unified with the matched tuple. Blocks if no matching tuple is available.
staticrd(TupleList,Tuple)rd(+list,?term) - onerd_list/2
Reads a tuple matching one of the patterns in TupleList from the tuple-space without removing it. Tuple is unified with the matched tuple. Blocks if no matching tuple is available.
staticrd_list(TupleList,Tuple)rd_list(+list,?term) - onefindall_rd_noblock/3
Returns a list of all instances of Template for tuples matching Tuple in the tuple-space. The operation is atomic.
staticfindall_rd_noblock(Template,Tuple,List)findall_rd_noblock(?term,+term,?list) - onefindall_in_noblock/3
Removes and returns a list of all instances of Template for tuples matching Tuple in the tuple-space. The operation is atomic - all matching tuples are removed in one synchronized operation.
staticfindall_in_noblock(Template,Tuple,List)findall_in_noblock(?term,+term,?list) - oneProtected predicates
(no local declarations; see entity ancestors if any)
Private predicates
server_socket_/1
Stores the server socket descriptor.
dynamicserver_socket_(ServerSocket)server_socket_(?term) - zero_or_oneclient_connection_/3
Stores active client connections. Each client has an ID, input stream, and output stream.
dynamicclient_connection_(ClientId,InputStream,OutputStream)client_connection_(?term,?term,?term) - zero_or_moreaccept_hook_/1
Stores the optional accept hook goal to call when a client connects.
dynamicaccept_hook_(Hook)accept_hook_(?callable) - zero_or_oneserver_running_/0
Flag indicating the server is running.
dynamicserver_running_ - zero_or_oneserver_shutdown_/0
Flag indicating the server has received a shutdown request.
dynamicserver_shutdown_ - zero_or_onetuple_/1
Stores tuples in the Linda tuple space.
dynamictuple_(Tuple)tuple_(?term) - zero_or_morewaiting_/3
Stores blocked clients waiting for tuples. Records the client ID, request pattern, and output stream.
dynamicwaiting_(ClientId,Request,OutputStream)waiting_(?term,?term,?term) - zero_or_moreengine_counter_/1
Counter for generating unique client engine names.
dynamicengine_counter_(Counter)engine_counter_(?integer) - zero_or_oneclient_engine_/2
Maps client IDs to their corresponding threaded engine names.
dynamicclient_engine_(ClientId,EngineName)client_engine_(?term,?atom) - zero_or_moreclient_connection_input_/1
Stores the input stream for the client connection to the server.
dynamicclient_connection_input_(InputStream)client_connection_input_(?term) - zero_or_oneclient_connection_output_/1
Stores the output stream for the client connection to the server.
dynamicclient_connection_output_(OutputStream)client_connection_output_(?term) - zero_or_oneclient_timeout_/1
Stores the timeout value for blocking client operations. Value is either off or Seconds:Milliseconds.
dynamicclient_timeout_(Timeout)client_timeout_(?compound) - zero_or_onets_out/1
Synchronized predicate to add a tuple to the tuple space and wake waiting clients.
static, synchronizedts_out(Tuple)ts_out(+term) - onets_in/4
Synchronized predicate to remove a matching tuple or register a waiting client.
static, synchronizedts_in(Tuple,ClientId,OutputStream,Found)ts_in(+term,+term,+term,-compound) - onets_in_noblock/2
Synchronized predicate to try removing a matching tuple without blocking.
static, synchronizedts_in_noblock(Tuple,Found)ts_in_noblock(+term,-compound) - zero_or_onets_in_list/4
Synchronized predicate to remove a tuple matching one of multiple patterns or register a waiting client.
static, synchronizedts_in_list(TupleList,ClientId,OutputStream,Found)ts_in_list(+list,+term,+term,-compound) - onets_rd/4
Synchronized predicate to read a matching tuple or register a waiting client.
static, synchronizedts_rd(Tuple,ClientId,OutputStream,Found)ts_rd(+term,+term,+term,-compound) - onets_rd_noblock/2
Synchronized predicate to try reading a matching tuple without blocking.
static, synchronizedts_rd_noblock(Tuple,Found)ts_rd_noblock(+term,-compound) - zero_or_onets_rd_list/4
Synchronized predicate to read a tuple matching one of multiple patterns or register a waiting client.
static, synchronizedts_rd_list(TupleList,ClientId,OutputStream,Found)ts_rd_list(+list,+term,+term,-compound) - onets_findall_rd_noblock/3
Synchronized predicate to collect all tuples matching a pattern.
static, synchronizedts_findall_rd_noblock(Template,Tuple,List)ts_findall_rd_noblock(+term,+term,-list) - zero_or_morets_findall_in_noblock/3
Synchronized predicate to collect and remove all tuples matching a pattern.
static, synchronizedts_findall_in_noblock(Template,Tuple,List)ts_findall_in_noblock(+term,+term,-list) - zero_or_moreOperators
(none)