You are looking at historical revision 21368 of this page. It may differ significantly from its current revision.
This is an extension of the mailbox-threads egg to allow communication between remote threads via zmq. By default, the Scheme write/read procedures are used for serialization so not all objects can be sent. You may want to override the serializer/deserializer parameters to s11n's serialize/deserialize functions to be able to send record, lambdas etc.
All procedures exported by mailbox-threads are also exported by remote-mailbox-threads, the only difference being that thread-send can also send messages to remote threads (see connect-remote-thread on how to connect to a remote thread). The functions documented here are only those which are provided additionally.[procedure] (publish-thread! thread . endpoints)
Publish thread via endpoints (a list of zmq endpoint strings). For each invocation of publish-thread! a thread with a message loop for the given endpoints is started.[procedure] (connect-remote-thread . endpoints)
Connect to remote thread(s) at endpoints (a list of zmq endpoint strings). The return value will be a remote-thread record which can be sent messages just like normal threads using thread-send. The remote threads must be published by using publish-thread! at the remote side. If more than one endpoint is given in endpoints, messages will be sent round-robin style thus you should make sure that all messages sent to the remote thread can be handled by any of the given endpoints.[parameter] (serializer [FN])
The function used for serializing objects which are to be sent. It must accept one argument (the object to be serialized) and write the serialized representation to (current-output-port). Default: write.[parameter] (deserializer [FN])
The function used for deserializing received messages. It should read the serialized data stream from (current-input-port) and return the deserialized object. Default: read.
(use remote-mailbox-threads) (publish-thread! (current-thread) "tcp://127.0.0.1:12345" "ipc:///tmp/nomnom") (print "waiting for things to consume") (let loop ((msg (thread-receive))) (display "nom nom nom:") (print msg) (loop (thread-receive)))
(use remote-mailbox-threads) (define consumer (connect-remote-thread "tcp://127.0.0.1:12345")) (define another-consumer (connect-remote-thread "ipc:///tmp/nomnom")) (thread-send consumer 'carrot) (thread-send another-consumer 'egg)
Note that the producer connects to two different remote threads, both of which refer to the same exported thread of the producer.
Copyright (c) 2010, Moritz Heidkamp All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the <organization> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.