In the zeromq C library, each socket is supposed to be used in a single thread. While this is reasonable given the message-oriented paradigm of zeromq, it is an issue in a language such as Common Lisp where we have a REPL to interact with the application. In Slime, the Common Lisp backend can evaluate each expression is a separate thread. Therefore calling zmq functions from the REPL is definitely not a good idea.
With the new version of lisp-zmq (1.3.0), you can use the
:thread-safe key argument when creating a socket:
(zmq:socket context :pub :thread-safe t)
In that case, operations on this socket will be protected by a mutex.
While this mutex makes socket functions safe, you may need to manually lock sequences of operations, for example if you want to receive a whole multipart message in a thread. For this reason, the macro
with-socket-locked has been added.
The bordeaux-threads library is used for portable mutexes, it is a new dependency of lisp-zmq.
Note that sockets are now objects, and not foreign pointers to the underlying zeromq sockets.
socket-lock return respectively the foreign pointer to the zeromq socket and the mutex of a socket.