[zeromq-dev] zmq multithread bug
Guo, Yanchao
Yanchao.Guo at sac.com
Wed Jan 27 08:58:10 CET 2010
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.
Also, I have put my lock before the the call to send, isn't it enough to make it thread-safe?
Yanchao
-----Original Message-----
From: Martin Sustrik [mailto:sustrik at 250bpm.com]
Sent: Wed 1/27/2010 2:56 AM
To: Guo, Yanchao
Cc: zeromq-dev at lists.zeromq.org
Subject: Re: [zeromq-dev] zmq multithread bug
Hi Guo,
> Hi All, the sample code below publishes data into socket from two
> thread: One thread publishes "dummy", the other one publishes "from
> server: 1". But the data is not properly received on the other side,
> this is the print out:
The sockets are strictly non-thread-safe. There's no locking involved on
socket operations what makes 0mq as fast as it is. Therefore you
shouldn't write to a single socket from 2 threads.
If what you need is delivering messages from N sources to M destinations
via TCP you can either:
1. Explicitly connect from each receiver to each sender or vice versa.
Unless you have a stable set of client this would be a management nightmare.
2. Use zmq_forwarder device. All the senders will connect and send
messages to the device. All the receivers will connect and read messages
from the device. See examples/chat example.
3. Use multicast bus, either PGM or UDP. However, multicast has its own
set of drawbacks, so it not absolutely needed for perf reasons, go
rather with option 1 or 2.
Martin
DISCLAIMER: This e-mail message and any attachments are intended solely for the use of the individual or entity to which it is addressed and may contain information that is confidential or legally privileged. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and permanently delete this message and any attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100127/7101a9a6/attachment.htm>
More information about the zeromq-dev
mailing list