[zeromq-dev] zmq multithread bug

Martin Sustrik sustrik at 250bpm.com
Wed Jan 27 09:06:12 CET 2010


Guo,

> Ok. I read the zmq_init document and it states that "Initialises 0MQ 
> context. app_threads specifies maximal number of application threads 
> that can own open sockets at the same time", so I thought multi-thread 
> is supported.

Yes. That means that you can open socket A from thread 1 and socket B 
from thread 2. If you specified just 2 application threads, attempt to 
open socket C from thread 3 will fail.

Still, each socket should be used from at most one thread. See 
zmq_socket(3) man page:

"Note that each socket is owned by exactly one thread (the one that it 
was created from) and should not be used from any other thread."

> Also, I have put my lock before the the call to send, isn't it enough to 
> make it thread-safe?

No, it won't. Socket is simply exclusive to the thread that created it.

Martin


More information about the zeromq-dev mailing list