[zeromq-dev] Help forwarding asynchronous events through ZeroMQ

Martin Sustrik sustrik at 250bpm.com
Fri Aug 5 09:29:21 CEST 2011


Hi Lucas,

> 1. I can't just open a permanent socket and write to it, as sockets
> aren't thread safe. Or could I? If the underlying asynchronous events
> have their own lock (such as a pre-existing logging system), could I
> rely on that lock for non-concurrent access to the socket?

Yes, you can. What happens is that socket gets migrated to a new 
(calling) thread each time an event is sent. mutex enclosing the socket 
will ensure that appropriate memory barriers are executed. Don't forget 
that other operations on the socket (say zmq_close) have to be guarded 
by the mutex as well.

Martin



More information about the zeromq-dev mailing list